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
精彩评论