0
Can we make infinite loop from if else? If yes what will be the minimum lines of code needed?
Make an infinite loop by using only if else with minimum lines of code
5 Réponses
+ 3
With ONLY if...else, can't see how.
As Bebida Roja said if you use goto (not very appreciated) you could achieve that but it would still be a loop achieved with another statement than your if.
Or if your if...else statement is part of a function, using a recursion call on the function in your statement could also make an infinite loop. But then again it is a disguised loop (i.e. no for nor while used) and it doesn't come from the if...else statement in itself...
+ 9
Do you mean without using any loop and only using if...else control statements ? Nope.
+ 2
An endless loop is a special kind of loop. If/else is a one time decision and not a loop so I don't see how that would be possible.
+ 1
You can if you use goto
0
public function infinite _loop(){ $x = (1 != 0)?infinite _loop():0; }
infinite_loop();