What is the result of executing of following code?

<?php
for ($i = 0; $i < 5; ++$i) {
    if ($i == 2) continue;
    print "$i";
}
?>
Explanation
++$i / $i++ always run after the loop, that is means result of loop are equal to:

$i = 0;
while ($i < 5) {
if ($i != 2) {
print "$i"; 
}
$i++; // ++$i 
}
In case we add the "print" to loop parameters the result will be different:

for ($i = 0; $i < 5; print ++$i) { } // 12345

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
PHP quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes