exit 2 loops (repeats)

Hello

Is it possible to exit 2 loops instead of only 1.

I have two loops, in the inner loop (loop2) i perform a test , if test is true then i want to exit the inner loop and the outer loop (loop 1)

Right now i do it like this:

loop1

loop2
if points > 200 then exit --test points once
end loop2

if points > 200 then exit --test points twice
end loop1

But this means i have to perform the same test twice, and i want to be able to do the test only once (in loop 2) and then exit both loops

Maybe something like this will work. It sets a flag that tells the loops when to terminate.

set counter to 0
set exit_ to false

repeat until exit_ is true
	repeat until exit_ is true
		set counter to counter + 1
		display dialog "Inner loop " & counter
		if counter is 5 then set exit_ to true
	end repeat
	display dialog "Outer loop " & counter
end repeat

– Rob

Yes that will do the trick
Thanks

Hi all :slight_smile:
Also, you can make any “repeat” loops in the “try” statement, and “exit” from them with the “error” command, for exemple:

try
	repeat
		repeat with Nro from 1 to 20
			repeat 5 times
				if Nro > 15 then error
			end repeat
		end repeat
	end repeat
end try

:wink:

That’s also a handy solution