0

Whats wrong with "Take a short cut" in php

$x = 0; while($x<=7) { $x++; } echo $x;

7th Aug 2017, 6:21 PM
Sudeep D.C
Sudeep D.C - avatar
3 Respuestas
+ 1
It outputs 8 after the loop.
7th Aug 2017, 6:39 PM
ChaoticDawg
ChaoticDawg - avatar
0
how? please explain
8th Aug 2017, 5:03 AM
Sudeep D.C
Sudeep D.C - avatar
0
In the last iteration of the while loop, the comparison checks to see if $x is less than or equal to 7. $x is 7 and the loop is entered and $x is incremented to 8. Then the comparison is checked again, but 8 is greater than 7, so the while loop is exited and $x is echoed outputting 8
8th Aug 2017, 5:09 AM
ChaoticDawg
ChaoticDawg - avatar