Will this cause infinite loop ..If yes/no ..explain | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Will this cause infinite loop ..If yes/no ..explain

<? php $x=1; while (2> $x) { $x++; $x-=2; }

29th May 2017, 8:34 AM
Deepak Yadav
Deepak Yadav - avatar
2 Respostas
+ 10
<? php $x=1; while (2> $x) { $x++; $x-=2; } can be rewritten as <? php $x=1; while ($x< 2) { $x-=1; } meaning $x is reduced by 1 in every iteration. So, $x always stays less than 2. Thus, it's an infinite loop.
29th May 2017, 9:41 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 7
šŸ˜ you soustrat x value end loop now $x is always 1
29th May 2017, 8:41 AM
Abbackr
Abbackr - avatar