<div dir="ltr"><div class="gmail_quote">On Fri, Mar 9, 2012 at 8:41 AM, Gabor Szabo <span dir="ltr"><<a href="mailto:gabor@szabgab.com">gabor@szabgab.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
use strict;<br>
use warnings;<br>
use v5.10;<br>
<br>
my $i = 0;<br>
for ($i=0; $i <= 9; $i++) {<br>
#say $i;<br>
}<br>
say $i; # 10<br>
<br>
my $j = 0;<br>
for $j (0..9) {<br>
# say $j;<br>
}<br>
say $j; # 0<br>
<br>
In the c-style for loop we kept the value *that failed the condition*<br>
but I don't think these cases are very interesting.<br>
<br>
Maybe something like this, when it is not clear up-front<br>
how will the loop end, is more interesting:<br>
<br>
my $k = 0;<br>
for $k (0..9) {<br>
# say $k;<br>
last if rand() < 0.2;<br>
}<br>
say $k; # always 0<br>
<br>
my $q = 0;<br>
for ($q=0; $q <= 9; $q++) {<br>
# say $q;<br>
last if rand() < 0.2;<br>
}<br>
say $q; # some random number between 0 - 9<br>
<br>
I think this is what Roman suggested.<br></blockquote><div><br>I guess in that situation, the C-style for() loop would be more beneficial, unless you have calculated values, which means it will be at least twice as slow and you would be better off adding a variable to catch the last desires index.<br>
<br></div></div></div>