条件语句

即 if 语句,在 AppleScript 中,条件语句有两种形式:

循环语句

与其他编程语言中的 forwhiledo 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.

list 类型或 record 类型数据的循环

repeat with loopVariable in list (or record)
    set variable to (contents of i)
    --do something
end repeat

在循环体中,loopVariable 将依次得到 item 1 of listitem 2 of list... 这样的指针,如果要得到具体的内容,需要使用 contents of loopVariable 来获得。