Do applescript repeat loops reflect changes instantly?

Posted by user1159454 on Stack Overflow See other posts from Stack Overflow or by user1159454
Published on 2012-04-03T22:52:33Z Indexed on 2012/04/03 23:28 UTC
Read the original article Hit count: 217

Filed under:
|
|

I'm making a script to open multiple folders in a directory, and it's not working as planned. I've tried outlining it and walking through the steps one by one pretending I'm the computer executing it but when I run it the outcome is very different.

It uses repeat and repeat with a lot. The repeat repeats for as long as there is ANYTHING in a certain array (I mean List) and the repeat with is INSIDE of the first repeat, which repeats it's own loop with everything in the array at that time.

Now, one of the actions of the repeat with loop is to change the array. Which I think would change the loop would it not?

Example

(foldList is A, B, C)

repeat until {}
repeat with folder_name in foldList
do something
set foldList to 1, 2, 3
end repeat
end repeat

What I would THINK that does is iterate through the first loop as "A", but before hitting the end it would change foldList to 1, 2, 3. So instead of going through the next loop as "B" I'd think it would go as "1" instead.

But if it did that then I don't think my manual walkthrough would be off by so much. So I'm under the assumption that in Applescript when you're in a repeat with, regardless of changing the List you WILL end that loop on the last item of the first List (before the list was replaced.) Is this right?

© Stack Overflow or respective owner

Related posts about arrays

Related posts about loops