
Estoy ejecutando un script que básicamente tiene un bucle dentro de un bucle. Necesito alguna forma de indicarle a este script que salga del bucle interno.
repeat
doxyz
repeat
doSoreWork
if signalPresent then
exit repeat
end if
end repeat
end repeat
He estado buscando pero AS no parece tener ese servicio. Una posible forma que se me ocurre es utilizar un archivo. El bucle interno podría monitorear su existencia y, si lo encuentra, romper el bucle. Es crudo y no me gusta. ¿Existe una mejor manera?
EDITAR:
he estado mirandoBash Scripts que usan señales para romper los bucles. Hasta ahora funciona bastante bien, aunque sigue siendo feo :)
Respuesta1
Puedes probar la existencia de algo al principio del bucle, usando while
por ejemplo, esto se contará en voz alta, siempre que haya un archivo en el escritorio llamado 'tester.rtf'.
set fileTarget to (path to desktop folder as text) & "tester.rtf"
tell application "System Events"
set x to 1
repeat while (exists file fileTarget)
set x to x + 1
say x
end repeat
end tell