I was doing something where I needed to have two different increments happening in my "for" loop.
I was doing it like this, because I didn't know any better:
$j=0; for( $i=0; $i<20 ; $i++){ print "\$i = $i and \$j = $j"; $j++ }
but then someone pointed out to me that I could have more than one thing in the three arguments to "for", separated with commas:
for( $i=0,$j=0; $i<20,$j<20 ; $i++,$j++){ print "\$i = $i and \$j = $j"; }
and not only that but I found that "and" and "or" statements worked too:
for( $i=0,$j=0; $i<20 or $j<20 ; $i++,$j++){ print "\$i = $i and \$j = $j"; }
for( $i=0,$j=0; $i<20 and $j<20 ; $i++,$j++){ print "\$i = $i and \$j = $j"; }
OK, just so I can make this into a question, I look up "for" and of course it says "for (EXPR; EXPR; EXPR)", but where's my clue that my EXPR can be a set of statements separated by commas?
I obviously can't separate them with semicolons, but how was I supposed to figure out that commas were the answer?
--
Weaselling out of things is important. It's what separates us from the animals ... except the weasel.
In reply to Newbie realisation about by Cody Pendant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |