Simple question about counter Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
HiSoKa
Posts: 480
Joined: 27 Jan 2020, 15:43

Simple question about counter

Post by HiSoKa » 02 Dec 2022, 16:36

Hello,
How can I make N skip the value which assigned to a variable

Code: Select all

var := 3
n   := 0

Loop, 10
{
   n++
   MsgBox, % n
}

/*
Outputs
1
2
3    <===
4
5
6
7
8
9
10

Wanted outputs:
1
2
4
5
6
7
8
9
10
*/

User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: Simple question about counter  Topic is solved

Post by boiler » 02 Dec 2022, 16:54

Code: Select all

var := 3
n   := 0

Loop, 10
{
   n++
   if (n = var)
      continue
   MsgBox, % n
}

User avatar
HiSoKa
Posts: 480
Joined: 27 Jan 2020, 15:43

Re: Simple question about counter

Post by HiSoKa » 02 Dec 2022, 16:58

Thanks for the quick reply..
The code Works fine now.

User avatar
HiSoKa
Posts: 480
Joined: 27 Jan 2020, 15:43

Re: Simple question about counter

Post by HiSoKa » 04 Dec 2022, 03:19

Hi @boiler,
I'm having a problem with this code, My problem is that if a condition (n = var) is met
It seems the code do break for one loop then i get a gap in the value of a_index, This I do not want to happen, I want to get a serial value of the A_Index without any gaps between the numbers.

How can I avoid this thing.
This is the code:

Code: Select all

var := 3
n   := 0

Loop, 10
{
   n++
   if (n = var)
      continue
   MsgBox, n Var is:  %n% `n`nA_index Var is:  %A_Index%
}
Esc::ExitApp

/*
After condition met the Outputs is:
n Var is: 4
A_index Var is : 4

Wanted outputs:
n Var is: 4
A_index Var is : 3
*/
This is my attempt but it didn't work:

Code: Select all

var := 3
n   := 0

Loop, 10
{
   n++
   if (n = var)
	{
      continue
	  New_A_index--
	  ;New_A_index := A_Index -1  		; This also didn't work
	}
	New_A_index := A_Index
	MsgBox, n Var is:  %n% `n`nA_index Var is:  %New_A_index%
}
Esc::ExitApp

Thank you In advance...

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Simple question about counter

Post by Rohwedder » 04 Dec 2022, 03:42

Hallo,
perhaps?:

Code: Select all

var := 3
n   := 0

Loop, 10
{
   ++n=var?n++ ; or  n+=var=++n
   MsgBox, n Var is:  %n% `n`nA_index Var is:  %A_Index%
}
Esc::ExitApp

User avatar
HiSoKa
Posts: 480
Joined: 27 Jan 2020, 15:43

Re: Simple question about counter

Post by HiSoKa » 04 Dec 2022, 03:59

wonderful Thanks so much Rohwedder ,
But how to show, for example, a MsgBox if the condition is met, like this line:

Code: Select all

if (n = var)
 MsgBox, The condition is met
This is The code that I wrote after the modification:

Code: Select all

var := 3
n   := 0

Loop, 10
{
   n++
   if (n = var)
	{
	   ++n=var?n++
		continue
	}
	New_A_index := A_Index
	MsgBox, n Var is:  %n% `n`nA_index Var is:  %New_A_index%
}
Esc::ExitApp
Its problem is that it skips var 4 also, but in my case it should only skip var 3

User avatar
HiSoKa
Posts: 480
Joined: 27 Jan 2020, 15:43

Re: Simple question about counter

Post by HiSoKa » 04 Dec 2022, 04:12

Sorry @Rohwedder my last question was wrong,
met condition (n = var) impossible,
Now I can use if statement inside the loop to achieve what I want with other variables.

Thanks again, and I'm really amazed at The numbers of the lines you shortened for me

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Simple question about counter

Post by Rohwedder » 04 Dec 2022, 04:17

Then perhaps?:

Code: Select all

var := 3
n   := 0

Loop, 10
{
   ++n=var?(n++,MsgBox("The condition is met"))
   MsgBox, n Var is:  %n% `n`nA_index Var is:  %A_index%
}
Esc::ExitApp

MsgBox(Text) {
	MsgBox, %Text%
}

User avatar
HiSoKa
Posts: 480
Joined: 27 Jan 2020, 15:43

Re: Simple question about counter

Post by HiSoKa » 04 Dec 2022, 04:25

That's what I meant. Thank you again Rohwedder

Post Reply

Return to “Ask for Help (v1)”