in other programm languages there is a construct like "for (i=0 till i=5)" or something like that.
a for loop that does the for loop for values i=0, i=1,...,i=4,i=5.
is there an equivalent thingie in autohotkey?
saw the for page but it talsk about objects and stuff which confuses me :-/
the background for my answer:
I want to find a pixel with a specific color in an area.
and dont wanna use pixel search for that purpose but do it pixel per pixel.
so I planned to do t with 2 for loops:
totestcolor:=0xdd03d0
for i=a till b{
for j=c till d{
CheckIfRightColor (color,i,j)
}
}
something like that.
how would I write the for loops right?
simple for number loop
-
- Posts: 440
- Joined: 28 Apr 2018, 21:59
Re: simple for number loop
In this case it sounds like you just want to use regular loops, https://www.autohotkey.com/docs/commands/Loop.htm
Autohotkey starts at index 1 rather than zero, and a built in variable A_Index will give you a current count of the loop you are in so in your example it would look something like this
Autohotkey starts at index 1 rather than zero, and a built in variable A_Index will give you a current count of the loop you are in so in your example it would look something like this
Code: Select all
totestcolor:=0xdd03d0
loop, 3
{
outerLoop := A_Index ;Only needed if you need to keep count of the outer loop
loop, 3
{
CheckIfRightColor (color,i,j)
}
}
-
- Posts: 4
- Joined: 20 Jun 2019, 08:49
Re: simple for number loop
If I understand what he's trying to do, he does need to track the outer loop and inner loop. So, adding to your work:MannyKSoSo wrote: ↑20 Jun 2019, 10:30In this case it sounds like you just want to use regular loops, https://www.autohotkey.com/docs/commands/Loop.htm
Autohotkey starts at index 1 rather than zero, and a built in variable A_Index will give you a current count of the loop you are in so in your example it would look something like thisCode: Select all
totestcolor:=0xdd03d0 loop, 3 { outerLoop := A_Index ;Only needed if you need to keep count of the outer loop loop, 3 { CheckIfRightColor (color,i,j) } }
Code: Select all
totestcolor := 0xdd03d0
loop, 3 ; change this to be your high value - the high value for 'i' in your example (this will curently run from 1 to 3)
{
oLoop := A_Index
loop, 3 ; change this to be your other high value - the high value for 'j' in your example
{
iLoop := A_Index
CheckIfRightColor (color, oLoop, iLoop)
}
}
Re: simple for number loop
yeah, you got it.
the same concept as if I wanted to go through a 2 layer array
like {{1,2}{3,4}}
I'll try your concept how it work.
and that A_Index always just refers to the current index of the innermost loop?
let's say i wanted i and j to go from 100 to 400 instead.
sur I could change the things inside
(when 1<=i,j<=301) the inside then being ((i-1)+99,(j-1)+99).
so do i see it right that what I wanted basically doesnt exist directly, like some for loop going through a certain index range, where i can always use the current index?
the same concept as if I wanted to go through a 2 layer array
like {{1,2}{3,4}}
I'll try your concept how it work.
and that A_Index always just refers to the current index of the innermost loop?
let's say i wanted i and j to go from 100 to 400 instead.
sur I could change the things inside
(when 1<=i,j<=301) the inside then being ((i-1)+99,(j-1)+99).
so do i see it right that what I wanted basically doesnt exist directly, like some for loop going through a certain index range, where i can always use the current index?