note 58779 deleted from control-structures.for by danbrown
| From: | danbrown@php.net | Date: | Mon, 07 Dec 2009 16:05:45 +0000 |
| Subject: | note 58779 deleted from control-structures.for by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-163652@lists.php.net to get a copy of this message | ||
Note Submitter: Maciek
----
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..