i dont understand, why the echo is not just one time , i missed 1++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

i dont understand, why the echo is not just one time , i missed 1++

<?php $i = 1; while ($i =7) { echo "The value is $i <br />"; $i++; } ?>

24th Nov 2019, 12:41 PM
Petra Noé
Petra Noé - avatar
2 Answers
+ 3
Petra Noé /* <?php $i = 1; //initially assigned value 1 // while loop will execute till $i = 7 while ($i = 7) //while condition is true(non zero) so it will always execute the code and print till the time limit exceeds { echo "The value is $i <br />"; //post increment the value in which first value store in variable then it is incremented by 1 $i++; } ?> */ <?php $i = 1; while ($i < 7)//take while condition less then 7 to print 1 to 6 { echo "The value is $i <br />"; $i++; } ?> In your code while loop value is true non zero so while loop will be execute always
24th Nov 2019, 1:03 PM
GAWEN STEASY
GAWEN STEASY - avatar
0
thx !!!!
24th Nov 2019, 1:15 PM
Petra Noé
Petra Noé - avatar