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

26th Sep 2018, 5:52 AM
Adarsh Pathak
Adarsh Pathak - avatar
5 odpowiedzi
+ 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...
26th Sep 2018, 6:19 AM
dhm
+ 9
Do you mean without using any loop and only using if...else control statements ? Nope.
26th Sep 2018, 5:59 AM
Nikhil
Nikhil - avatar
+ 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.
26th Sep 2018, 6:01 AM
Anna
Anna - avatar
+ 1
You can if you use goto
26th Sep 2018, 6:10 AM
Bebida Roja
Bebida Roja - avatar
0
public function infinite _loop(){ $x = (1 != 0)?infinite _loop():0; } infinite_loop();
26th Sep 2018, 7:00 AM
Kirtan
Kirtan - avatar