in reply to Re: which loop is better
in thread which loop is better
is basicly the same asforeach (@array) { dosomethingto($_); }
I find the first simpler and the second more powerful but more noisy for most uses.for (my $i = 0; $i < @array; $i++) { dosomethingto($array[$i]); }
asmy $fs = ''; for (my $f = 0; $f < 10; $f++) { #last if $f == 7; next if $f == 5; print "f: $f\n"; $fs .= "$f "; redo if length($fs) == 6; } print "fs: $fs\n";
They do the same thing, and I understand both of them. So obviously since they are both in Perl they are both equaly correct. </sarcasm>my $gs = ''; FOR_INIT: my $g = 0; goto FOR_TEST; FOR_NEXT: $g++; FOR_TEST: goto FOR_LAST unless $g < 10; FOR_REDO: #goto FOR_LAST if $g == 7; goto FOR_NEXT if $g == 5; print "g: $g\n"; $gs .= "$g "; goto FOR_REDO if length($gs) == 6; goto FOR_NEXT; FOR_LAST: print "gs: $gs\n";
|
|---|