note 16150 added to control-structures.for
| From: | cleong at letstalk dot com | Date: | Thu, 18 Oct 2001 00:00:57 +0000 |
| Subject: | note 16150 added to control-structures.for | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-19072@lists.php.net to get a copy of this message | ||
You should always cast the looping index to an int if you're initializing it with another
variable. Otherwise you risk getting caught in an infinite loop. The following will run till Kingdom
comes:
function a($start_index) {
for($i = $start_index; $i < 10; $i++) echo "\$i = $i\n";
}
a('Eternity!');
More subtle is a(false), which also loops forever.
--
http://www.php.net/manual/en/control-structures.for.php
http://master.php.net/manage/user-notes.php?action=edit+16150
http://master.php.net/manage/user-notes.php?action=delete+16150
http://master.php.net/manage/user-notes.php?action=reject+16150