Wednesday, July 24, 2013

Continue in the loop

continue keyword is use for continue the current loop. Php also accepts an optional argument to continue several levels of loop.

Ok. Check following code.

for ($i = 0; $i < 5; ++$i) {
    if ($i == 2)
        continue
    print "$i\n";
}

What you expect as the result?
0
1
3
4
But result is...
2
Because
continue print "$i\n"; 
is a single expression. For your expected result you should add a ; after the continue.

I have found this joke from php manual

No comments:

Post a Comment