
我正在運行一個基本上在循環內有一個循環的腳本。我需要某種方法來指示該腳本脫離內部循環。
repeat
doxyz
repeat
doSoreWork
if signalPresent then
exit repeat
end if
end repeat
end repeat
我一直在尋找,但AS似乎沒有任何這樣的設施。我能想到的一種可能的方法是使用文件。內部循環可以監視它的存在,如果發現則中斷循環。它很粗糙,我不喜歡它。有沒有更好的辦法?
編輯:
我一直在看Bash 腳本使用訊號來打破循環。到目前為止,它運行得相當好,儘管它仍然很醜:)
答案1
您可以使用 while 來測試循環頭部是否存在某些內容
例如,只要桌面上有一個名為「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