note 58779 added to control-structures.for

From: Date: Tue, 15 Nov 2005 19:12:58 +0000
Subject: note 58779 added to control-structures.for
Groups: php.notes 
Request: Send a blank email to php-notes+get-98626@lists.php.net to get a copy of this message
in reply to mbvlist about his loop: <?php for($i=0; $i < $max; $i++ && print 'increment,') { do_something(); echo " i = $i\n"; } echo "finally, i = $i\n"; ?> Your loop works as you observed, because php evaluates the following as expression: ($i++ && print 'increment) When $i=0, $i++ returns false, so the second part of the expression (print 'increment') is not evaluated, since there is no output. Since $i > 0 returns true, your print will be evaluated and you will see output.. ---- Manual Page -- http://www.php.net/manual/en/control-structures.for.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+58779 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58779&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58779&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58779&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58779&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58779&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58779&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58779&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+58779&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#98626) next »