simple for number loop

Get help with using AutoHotkey and its commands and hotkeys
densch
Posts: 49
Joined: 29 May 2018, 15:10

simple for number loop

20 Jun 2019, 10:14

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?
MannyKSoSo
Posts: 437
Joined: 28 Apr 2018, 21:59

Re: simple for number loop

20 Jun 2019, 10:30

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

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)
	}
}
Kenn_Guilstorf
Posts: 4
Joined: 20 Jun 2019, 08:49

Re: simple for number loop

20 Jun 2019, 11:28

MannyKSoSo wrote:
20 Jun 2019, 10:30
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

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)
	}
}
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:

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)
	}
}
densch
Posts: 49
Joined: 29 May 2018, 15:10

Re: simple for number loop

20 Jun 2019, 12:48

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?

Return to “Ask For Help”

Who is online

Users browsing this forum: A_Birdi, Bing [Bot], flyingDman, gDosomething, niky45 and 63 guests