How can i do this in autohotkey?
Thank you
for i=1 to 12 { MsgBox, hello! %i% }
Help file didn't help:
For Key [, Value] in Expression
for i=1 to 12 { MsgBox, hello! %i% }
Loop 12 MsgBox, hello! %A_Index%
You mean that
"for i=5 to 12" is equal to "Loop 8"
But i use variable "i" in my code.
for example
"if i<7
then ....
elseif i>10
then ....
end"
i := 5 Loop 8 { ; i + 8 (12) if (i < 7) continue ; then ... else if (i > 10) continue ; then ... i += 1 ; change increment }
loop 8 { i := A_Index+4 ; 5 start with + 1 increment if (i < 7) continue ; then ... else if (i > 10) continue ; then ... }
Loop % (i := 5) + 3 ; loops 5+3 times, i = 12 at the break i += 1
Why? Loop is essentially the same without an inline increment.Thank you Solar for helps.
But a "for-loop" would be very helpful if autokey had it.
Regards
Why? Loop is essentially the same without an inline increment.Thank you Solar for helps.
But a "for-loop" would be very helpful if autokey had it.
Regards
... based on this post:But a "for-loop" would be very helpful if autokey had it.
for i in list.new(5,12) MsgBox, %i% class List { New(Start, End, Step=1) { return {1:Start-Step, 2:End, 3:Step, base:this} } _NewEnum() { return this } Next(ByRef var) { return (var := this[1] := this[1] + this[3]) <= this[2] } }
If I got to the point that I wanted a for loop that badly (or classes or OOP in general), I'd use another language that does them naturally rather than that messfor i in list.new(5,12)
MsgBox, %i%
class List {
New(Start, End, Step=1) {
return {1:Start-Step, 2:End, 3:Step, base:this}
}
_NewEnum() {
return this
}
Next(ByRef var) {
return (var := this[1] := this[1] + this[3]) <= this[2]
}
}
for(var,start,step,end,sub) { %var% := start count := end-start+1 loop %count% { tooltip gosub % sub %var%:=%var%+step } }
for("i",5,1,12,"dothis") return dothis: MsgBox % i return