Exit the loop every time if it was done more than N times Topic is solved

Ask gaming related questions (AHK v1.1 and older)
Botsy
Posts: 19
Joined: 25 Aug 2020, 16:59

Exit the loop every time if it was done more than N times

07 Sep 2020, 16:14

Hello everyone! Could tell me plz, how you can exit the loop if it has been done more than N times?
There are two endless loops:

Code: Select all

Loop (first)
{
	Loop (second)
	{
		....
			if 
			{
				*If this if is done more than N times, exit the second loop and return to the first loop*
				break
			{
		else
			{
				....
			}
	}
}
If we add "if A_index> 8" to the "if", then we will indeed exit, though only once. Because when we get into the second loop again, A_index will already be greater than 8
Help ))
Last edited by BoBo on 07 Sep 2020, 16:26, edited 1 time in total.
Reason: Moved to Gaming section.
Kobaltauge
Posts: 264
Joined: 09 Mar 2019, 01:52
Location: Germany
Contact:

Re: Exit the loop every time if it was done more than N times

07 Sep 2020, 16:26

I would use an index variable. You can define for every loop a separate one. Increase it and break at your defined counter.
Botsy
Posts: 19
Joined: 25 Aug 2020, 16:59

Re: Exit the loop every time if it was done more than N times

07 Sep 2020, 16:35

Kobaltauge wrote:
07 Sep 2020, 16:26
I would use an index variable. You can define for every loop a separate one. Increase it and break at your defined counter.
can you explain a little bit more ?
Kobaltauge
Posts: 264
Joined: 09 Mar 2019, 01:52
Location: Germany
Contact:

Re: Exit the loop every time if it was done more than N times  Topic is solved

07 Sep 2020, 17:25

Code: Select all

counter_first := 0

Loop, 100
{
	MsgBox,,,First %counter_first%
	counter_second := 0
	Loop, 100
	{
		MsgBox,,, Second %counter_second%
		if counter_second > 9
			Break
		counter_second += 1
	}
	if counter_first > 10
		Break
	counter_first += 1
}
Now you have only to know where to reset your counter variables, what are the breaking condition for every loop and how big your steps are.
In this example the "second" loop, loops 10 times for every "first" loop. The loops are set to 100. But you could use an endless loop to.

hth
Botsy
Posts: 19
Joined: 25 Aug 2020, 16:59

Re: Exit the loop every time if it was done more than N times

07 Sep 2020, 17:44

Kobaltauge wrote:
07 Sep 2020, 17:25

Code: Select all

counter_first := 0

Loop, 100
{
	MsgBox,,,First %counter_first%
	counter_second := 0
	Loop, 100
	{
		MsgBox,,, Second %counter_second%
		if counter_second > 9
			Break
		counter_second += 1
	}
	if counter_first > 10
		Break
	counter_first += 1
}
Now you have only to know where to reset your counter variables, what are the breaking condition for every loop and how big your steps are.
In this example the "second" loop, loops 10 times for every "first" loop. The loops are set to 100. But you could use an endless loop to.

hth
thank you very much, kind person!!! Now i understand )

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 50 guests