条件语句
if 条件 then
...
else if 条件 then
...
else
...
end if
举例:
set num to 14
if num is 13 then -- 不能使用== ,只能使用is表示相等
set num to 13 * 2
else if num is 14 then
set num to 14 * 2
else
set num to num * 5
end if
循环语句
语法1:
repeat 循环次数 times
end repeat
举例:
set num to 2
repeat 3 times
set num to num * 2
end repeat
语法2:
repeat with 计数变量 from 计数变量初始值 to 计数变量目标值 by 每次增量
end repeat
注:by省略时,默认值为1
举例:
set num to 2
repeat with i from 2 to 4 by 1 //i初值为2,每次增长1,直到4
set num to num * i
end repeat
语法3:
repeat while 条件
end repeat
举例:
repeat while num < 100
set num to num * 2
end repeat
语法4:
repeat until 条件
end repeat
举例
set num to 2
repeat until num > 100
set num to num * 2
end repeat
语法5:
repeat with 单个元素名 in 循环对象
end repeat
举例
set arr to {"张三", "李四", "王五", "谢六"}
set appendStr to ""
repeat with nameStr in arr
set appendStr to appendStr & nameStr
end repeat