in reply to Re: which loop is better
in thread which loop is better

for and foreach are synonyms. there really is no difference between them:
for (@arr[0..2]) { $_++; } foreach (my $i = 0; $i <= 2; $i++) { @arr[$i]++; }
will work just as well

Replies are listed 'Best First'.
Re^3: which loop is better
by dave_the_m (Monsignor) on Oct 04, 2004 at 11:09 UTC
    Err, I don't think what you say is very clear. For and foreach are synonyms, but either of them can be used to delcare two completely different loop contructs, ie the following two lines are identical to each other
    for (expr; expr; expr) block foreach (expr; expr; expr) block
    while the following two are identical to each other, but not to the first two lines above
    for (list) block foreach (list) block

    Dave.