开发者

How to get the index of a loop in Applescript?

开发者 https://www.devze.com 2023-03-10 20:19 出处:网络
I have a list of different length strings that I\'m looping: set my_list to {\"开发者_StackOverflowabc\", \"defg\", \"hi\", \"jklmno\"}

I have a list of different length strings that I'm looping:

set my_list to {"开发者_StackOverflowabc", "defg", "hi", "jklmno"}

repeat with the_item in my_list
    -- get index of the_item
end repeat

How can I find the index of the_item while I'm looping?


You can either introduce a counter and update it with each iteration through the loop:

set counter to 0
repeat with the_item in my_list
  set counter to counter + 1
  -- do stuff
end repeat

or use a different loop form:

repeat with n from 1 to count of my_list
  -- do stuff with (item n of my_list)
end repeat
0

精彩评论

暂无评论...
验证码 换一张
取 消