note 77815 deleted from control-structures.for by danbrown

From: Date: Mon, 07 Dec 2009 16:01:08 +0000
Subject: note 77815 deleted from control-structures.for by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-163643@lists.php.net to get a copy of this message
Note Submitter: david dot sledge at yahoo dot com ---- In response to mused.biz's comment: > Incrementing two variables together can also be achieved, eg: > > for ($j = "a", $k = "1"; $j <= "f", $k <= "6" ; > $j++, $k++) Note that the statement: $j <= "f" has absolutely no effect on this loop (which isn't to say it doesn't get evaluated), because it is separated from the following statement by a comma. If $j were to exceed the value "f" before $k exceeded "6", the loop would still continue. However, the statement: <?php for ( $i = 0; $i++, $i < 10; $i++ ) echo $i . '<br/>'; ?> will result in the following: 1 3 5 7 9 because $i is incremented before the condition is evaluated, in addition to it being incremented after the completion of each loop.

« previous php.notes (#163643) next »