note 102608 deleted from control-structures.goto by danbrown
[email protected] Thu, 24 Feb 2011 07:06:37 -0800
| Newsgroups | php.notes |
|---|---|
| Message-ID | <[email protected]> |
Note Submitter: adam dot pilorz at labsql dot pl
----
tweston at coldsteelstudios dot com, your "goto loop" is not while replacement, but "do ... while" replacement. In short - while structure can be not executed if when starting loop condition is not met, while your's "goto loop" executes once and then test the condition. In other words:
<?php
goto_loop:
$i++;
if( $i < 100 ) goto goto_loop;
?>
is identical to
<?php
do{
i++;
} while( $i < 100 );
?>
but isn't identical to
<?php
while( $i < 100 ){
$i++;
}
?>
When $i is set to 1000 before those loops, the first two will end with $i = 1001, while the third will end with $i = 1000.