重复比一个更小的步骤

Repeat with smaller steps than one

所以我有一个 Applescript repeat with 循环。它的范围从 1 到 10,每次记录数字:

repeat with i from 1 to 10
    log i
end repeat

输出如下:

(*1*)
(*2*)
(*3*)
(*4*)
(*5*)
(*6*)
(*7*)
(*8*)
(*9*)
(*10*)

但是,现在我希望 i 以 0.1 的步长从 1 到 2。是否有内置函数可以执行此操作,还是我必须使用解决方法?

However, now I want i to go from 1 to 2 in steps of 0.1. Is there a built-in function to do that or do I have to work with a workaround?

来自repeat with loopVariable (from startValue to stopValue)

语法

repeat with  loopVariable  from  startValue  to  stopValue [ by  stepValue ]

    [ statement ]...

end [ repeat ]

stepValue
指定在每次循环迭代后添加到 loopVariable 的值。您可以分配 integerreal 值; real 值四舍五入为 integer.

默认值:1


因此,当使用 [ by stepValue ] 时,此内置函数无法像您所表达的那样执行,因为它总是将 real 舍入为 integer

不是使用 repeat with from to 语法,而是使用 repeat while 并自己递增 索引变量

set i to 1.0
repeat while i ≤ 2.0
    log i
    set i to i + 0.1
end repeat

或者从 10 到 20 然后将 i 除以 10

repeat with i from 10 to 20
    log i / 10
end repeat