I have a list of different length strings that I'm looping:
set my_list to {"abc", "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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With