Re: repeat question
Re: repeat question
- Subject: Re: repeat question
- From: Nigel Garvey <email@hidden>
- Date: Thu, 13 Dec 2001 02:29:04 +0000
Thomas Myers wrote on Wed, 12 Dec 2001 16:44:46 -0500:
>
Does anyone know how to continue in a repeat statment without exiting.
>
>
repeat with aLine in {1,2,3,4}
>
if aLine = 3 then
>
continue
>
end if
>
log aline
>
end repeat
>
>
>
So what I want in this example is only 1, 2 and 4 logged out.
>
>
Yes I know i could do this by putting all of the stuff below the if in side
>
the if, but in my case it's LOTS and it would be more readable if I could
>
just tell it to continue to next repeat item.
How about putting the LOTS inside a separate handler?
Or there's Ray Robertson's famous trick (which Paul may have mentioned by
now) of lining the repeat with an inner, 1-times repeat. This indents
just as much as an 'if' block, and slows down the main repeat a little,
but it has the advantage that it can be exited at any point. Jumping out
of this inner loop takes you to the end of the main repeat, which then
commences its next iteration. Similarly if you don't jump out of it:
after performing its actions once, it simply falls through to the end of
the main repeat:
repeat with aLine in {1,2,3,4} -- main repeat
repeat 1 times -- inner, jumpoutofable structure
-- A few tests
if aLine mod 2 is 0 then exit repeat
-- blah blah blah
if aLine = 3 then exit repeat
-- aLine never will equal 3 of course because
-- it's a reference and 3's an integer, so:
if contents of aLine = 3 then exit repeat
end repeat
end repeat