Page 1 of 1

Calculation with Mode

Posted: 10 Jun 2022, 06:02
by hasantr

Code: Select all

Loop,16
	MsgBox % 5553 + A_Index + !Mod(A_Index,2)
In this process
"5554,5556,5558,5560,5562,5564,5566,5568,5570"
I'm waiting for a result. But why doesn't this happen?

Re: Calculation with Mode

Posted: 10 Jun 2022, 06:24
by garry
tried this

Code: Select all

Loop,16
  {
  aa:=5553 + A_Index 
  if (Mod(A_Index,2))
  e .= aa . "`r`n"
  }
msgbox,%e%
exitapp

Re: Calculation with Mode

Posted: 10 Jun 2022, 06:32
by RussF
hasantr wrote:
10 Jun 2022, 06:02

Code: Select all

Loop,16
	MsgBox % 5553 + A_Index + !Mod(A_Index,2)
In this process
"5554,5556,5558,5560,5562,5564,5566,5568,5570"
I'm waiting for a result. But why doesn't this happen?
Your code works for me, however the sequence I get is not what you are apparently expecting. I get:

5554, 5556, 5556, 5558, 5558, 5560, 5560, 5562, 5562...

which is correct, based on the logic of your code.

What are you expecting and not getting?

Russ

Re: Calculation with Mode

Posted: 10 Jun 2022, 06:33
by hasantr
Thank you. But I wonder why it's not working. I prefer a one line solution.

Re: Calculation with Mode

Posted: 10 Jun 2022, 06:36
by hasantr
RussF wrote:
10 Jun 2022, 06:32
hasantr wrote:
10 Jun 2022, 06:02

Code: Select all

Loop,16
	MsgBox % 5553 + A_Index + !Mod(A_Index,2)
In this process
"5554,5556,5558,5560,5562,5564,5566,5568,5570"
I'm waiting for a result. But why doesn't this happen?
Your code works for me, however the sequence I get is not what you are apparently expecting. I get:

5554, 5556, 5556, 5558, 5558, 5560, 5560, 5562, 5562...

which is correct, based on the logic of your code.

What are you expecting and not getting?

Russ
I don't want to get these pairs. I want to get each result individually. I could do it the other way, but I guess I'm stuck. I want to get 16 results and they must have increased by twos. It would be great to be able to solve it in one line.

Re: Calculation with Mode

Posted: 10 Jun 2022, 06:37
by RussF
What is not working? Exactly what do you expect to appear in your MsgBox?

Russ

Re: Calculation with Mode

Posted: 10 Jun 2022, 06:44
by hasantr
RussF wrote:
10 Jun 2022, 06:37
What is not working? Exactly what do you expect to appear in your MsgBox?

Russ
I expect two increments per loop starting with 5554. 5556 when A_index is 2, 5558 when A_index is 3

I realize that my logic is wrong.

Re: Calculation with Mode  Topic is solved

Posted: 10 Jun 2022, 07:39
by RussF
Try:

Code: Select all

MyVar := 5552
Loop, 16
   MsgBox % MyVar += 2
Or:

Code: Select all

Loop, 16
   MsgBox % 5552 + A_Index * 2
Russ

Re: Calculation with Mode

Posted: 25 Jun 2022, 15:29
by hasantr
Thank you. It was a very tired day, I was overlooking such a simple thing. I even missed your solution that day, then I figured it out and saw your message.