Verbosity and Lines of code
Alex Tweedly
alex at tweedly.net
Fri Jun 30 20:31:53 EDT 2017
That doesn't generalize to more than two levels (without many extra
lines of code) - you essentially have to number or label the repeat
loops, and check in many places whether the 'exitMe" variable has been
set to a higher level or not. And it's pretty fragile if additional
levels of repeat loop are added later.
and if the inner loop doesn't end immediately before the outer one, it
gets more messy - you need an exit check immediately after each "end
repeat" as well as at the top of the loop.
repeat with i = 1 to tSomething
repeat with k = 1 to tElse
if exitMe >= 2 then exit repeat
repeat with j = 1 to tSomethingElse
if exitMe = true then exit repeat
DoSomethingWith i,j
put 2 into exitMe
end repeat
if exitMe >= 2 then exit repeat
someOtherCode "here"
end repeat
if exitMe >= 1 then exit repeat
end repeat
(don't trust the above code - I have no idea whether "2" is the right
value to test for in those places :-)
-- Alex.
On 01/07/2017 00:59, Jim Lambert via use-livecode wrote:
>> RICHARDG wrote:
>>
>> This would allow us to exit a specific loop when loops are nested.
>>
>> I can't recall the specifics of his proposed syntax, but I remember
>> being impressed by how natural it seemed. Maybe it was along the lines of:
>>
>> repeat with i = 1 to tSomething named "MySomethingLoop"
>> repeat with j = 1 to tSomethingElse named "MyOtherLoop"
>> DoSomethingWith i,j
>> exit "MySomethingLoop"
>> end repeat
>> end repeat
>
> If we can tolerate 2 extra lines of code we can do nested exits this way:
>
> repeat with i = 1 to tSomething
> if exitMe = true then exit repeat
> repeat with j = 1 to tSomethingElse
> if exitMe = true then exit repeat
> DoSomethingWith i,j
> put true into exitMe
> end repeat
> end repeat
>
> Jim Lambert
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list