note 102608 deleted from control-structures.goto by danbrown
| From: | danbrown@php.net | Date: | Thu, 24 Feb 2011 15:06:37 +0000 |
| Subject: | note 102608 deleted from control-structures.goto by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-177289@lists.php.net to get a copy of this message | ||
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.