即 if 语句,在 AppleScript 中,条件语句有两种形式:
简单形式: if boolean then statement
复合形式:
if boolean1 then
statement1
else if boolean2 then
statement2
else
statement3
end if
与其他编程语言中的 for
、while
、do while
等循环类似。在 AppleScript 中,通过 repeat
来设置循环,并可以通过 exit
来退出循环。
repeat
--do something
end repeat
repeat n times
--do something
end repeat
repeat until boolean
--do something
end repeat
repeat while boolean
--do something
end repeat
repeat with loopVariable from startValue to stopValue by stepValue
--do something
end repeat
其中 loopVariable
不需要事先定义,stepValue
可以省略,省略时默认为 1.
repeat with loopVariable in list (or record)
set variable to (contents of i)
--do something
end repeat
在循环体中,loopVariable
将依次得到 item 1 of list
、item 2 of list
... 这样的指针,如果要得到具体的内容,需要使用 contents of loopVariable
来获得。