AppleScript-邏輯語句

條件語句

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

循環(huán)語句

語法1:
repeat 循環(huán)次數(shù) times
end repeat
舉例:

set num to 2
repeat 3 times
    set num to num * 2
end repeat

語法2:
repeat with 計(jì)數(shù)變量 from 計(jì)數(shù)變量初始值 to 計(jì)數(shù)變量目標(biāo)值 by 每次增量
end repeat
注:by省略時(shí),默認(rèn)值為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 單個(gè)元素名 in 循環(huán)對(duì)象
end repeat

舉例

set arr to {"張三", "李四", "王五", "謝六"}
set appendStr to ""
repeat with nameStr in arr
    set appendStr to appendStr & nameStr
end repeat
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容