in reply to Re: Re: for loop localisation bug?
in thread for loop localisation bug?
Ah! But what about
my $i; for $i ( 0 .. 10 ) { last if $i == 5; } print $i;
This could equally be optimised to remove the loop, but optimising the iterator away would be an error. In this case, the modification of the iterator is the primary purpose of the loop.
Of course, this is grossly simplified, the break condition would not be a comparison against a constant, and in the original scenario, the iterator was being used as the index into an array. In other words, the loop was searching an array for a particular value and the desired outcome is the index of the array at which it is found.
This isn't exactly an unusual use of a for loop
How would this be done in Turing?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: for loop localisation bug?
by demerphq (Chancellor) on Dec 29, 2003 at 19:22 UTC |