Using AND vs && in a for loop (Not related to precedence?)
Posted
by Peter
on Stack Overflow
See other posts from Stack Overflow
or by Peter
Published on 2010-02-03T04:22:39Z
Indexed on
2010/04/07
1:03 UTC
Read the original article
Hit count: 288
php
|logical-operators
Why is it that this code prints "Hello!" four times and then prints "1":
<?php
for ($i=1 AND $blah=1; $i<5; $i++) echo("Hello!");
echo($blah);
?>
While this doesn't print out "Hello!" at all and then prints "1":
<?php
for ($i=1 && $blah=1; $i<5; $i++) echo("Hello!");
echo($blah);
?>
I know AND and && have different precedences, but that doesn't seem to apply here. What am I missing? (I'm using a variant of the code above, since I will use $blah within the for loop, and I want to set the value for it). Thanks for any help!
© Stack Overflow or respective owner