下面是一个使用AppleScript的if-then语句和从列表中选择的示例代码:
set fruits to {"apple", "banana", "orange"}
set selectedFruit to "apple"
if selectedFruit is in fruits then
say "The selected fruit is available."
else
say "The selected fruit is not available."
end if
在上面的示例中,我们定义了一个水果列表fruits
,然后我们选择了一个特定的水果selectedFruit
。使用if-then语句,我们检查所选水果是否存在于水果列表中。如果存在,我们使用say
命令输出一条消息“所选水果可用”,否则会输出一条消息“所选水果不可用”。
请注意,is in
操作符用于检查一个值是否存在于列表中。如果存在,条件为真。你可以通过将selectedFruit
设置为列表中不存在的水果来测试代码的另一个分支。