This is a minor thing, that I bet all the senior monks know, but I only just found it out, and it was very useful, so maybe newbies like me might be interested.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.