How to get loop index in Applescript?

I have a list of string lengths 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_item index during a loop?

+6
source share
1 answer

You can enter a counter and update it with each iteration in a loop:

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

or use another form of loop :

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

Source: https://habr.com/ru/post/889967/


All Articles