0

我正在编写一个脚本来打开一个目录中的多个文件夹,但它没有按计划工作。我已经尝试过勾勒它并一步一步地走一遍,假装我是执行它的计算机,但是当我运行它时,结果却大不相同。

它使用重复和重复很多。只要某个数组(我的意思是列表)中有任何内容,重复就会重复,并且重复在第一个重复的内部,它会重复它自己的循环,当时数组中的所有内容。

现在,repeat with 循环的动作之一是更改数组。我认为这不会改变循环吗?

例子

(折叠列表为 A、B、C)

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

我会认为这样做是将第一个循环作为“A”进行迭代,但在结束之前它会将 foldList 更改为 1、2、3。所以我认为不是通过下一个循环作为“B”会改为“1”。

但如果它这样做了,那么我认为我的手动演练不会有太大的偏差。因此,我假设在 Applescript 中,当您重复使用时,无论更改列表,您都会在第一个列表的最后一项上结束循环(在替换列表之前)。这是对的吗?

4

1 回答 1

1

这将帮助您找到每个循环的价值。

set foldList to {"A", "B", "C"}
repeat 3 times
repeat with folder_name in foldList
    display dialog folder_name
    set foldList to {1, 2, 3}
end repeat
end repeat

版本 2:

set foldList to {"A", "B", "C"}
repeat 3 times
repeat with i from 1 to count of foldList
    display dialog item i of foldList
    set foldList to {1, 2, 3}
end repeat
end repeat
于 2012-04-03T23:17:18.643 回答