autohotkey 如何循环遍历数组

autohotkey how to cycle through array

我主要是 javascript 开发人员,我开始玩 authotkey。我在猜测是否有比我正在使用的方式更好的循环遍历数组的方法。基本上是这样的:

cycle(value,maxValue){
 value += 1
 if value not between 1 and %maxValue%
    value :=1
 return value
}

然后我这样使用它:

variable := cycle(variable,array.MaxIndex())

好像有点简陋。还有别的办法吗?

编辑

我看到我的描述不够清楚。我想要的是从数组中循环获取变量:当你要求下一个值时,你已经在最后一个,从头开始重新开始。

听起来你需要的是 for-loop

示例:

colors := Object("red", 0xFF0000, "blue", 0x0000FF, "green", 0x00FF00)
for key, value in colors
    s .= key "=" value "`n"
MsgBox % s

编辑:

根据您的评论,这可能更符合您的需要

index := 0
maxValue := 10

f3::
tooltip % index := cycle(index, maxValue)
return

cycle(index, maxValue)
{
    return index := mod(index + 1, maxvalue)
} 

希望对您有所帮助

既然blackholyman做的是对的,不是针对数组的。 这是我现在知道有效的方法:

i:=0,somearr:= ["bla","morebla","bla bla"]
;-- do whatever stuff here
somearr[i:=i>1?--i:somearr.MaxIndex()]