By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,614 Members | 1,674 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,614 IT Pros & Developers. It's quick & easy.

Why no error?

P: n/a
Why no error on this code?

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

Output is "2".
May be true must be "continue;"?
Sep 23 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
That's weird and interesting. You're right, you need the semicolon.

On Sep 23, 1:20*pm, "Andrew G. Koptyaev" <kopty...@gmail.comwrote:
Why no error on this code?

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

?>

Output is "2".
May be true must be "continue;"?
Sep 23 '08 #2

P: n/a
..oO(703designs)
>That's weird and interesting.
It's documented behaviour. The example was taken from the manual and
describes a situation which you should avoid.

Maybe it becomes clearer with a little rearrangement, it's still the
same code:

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

Since print is a special language construct and always returns 1, the
above is equivalent to

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

http://www.php.net/manual/en/control...s.continue.php
>You're right, you need the semicolon.
Yep.

Micha
Sep 23 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.