ghi*_*man 9 applescript loops list
我有一个不同长度字符串的列表,我正在循环:
set my_list to {"abc", "defg", "hi", "jklmno"}
repeat with the_item in my_list
-- get index of the_item
end repeat
Run Code Online (Sandbox Code Playgroud)
我如何在循环时找到the_item的索引?
Mic*_*ber 17
您可以引入一个计数器,并通过循环每次迭代更新它:
set counter to 0
repeat with the_item in my_list
set counter to counter + 1
-- do stuff
end repeat
Run Code Online (Sandbox Code Playgroud)
或使用不同的循环形式:
repeat with n from 1 to count of my_list
-- do stuff with (item n of my_list)
end repeat
Run Code Online (Sandbox Code Playgroud)