odd or even

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Calvin
Posts: 48
Joined: 22 Jul 2016, 01:11

odd or even

11 Feb 2019, 08:47

Hallo

I have a array arrDataFile where I have to do some thing at every other number in the array.

loop & arrDataFile.MaxIndex()
{
if A_Index = 1 {}
elseif A_Index / 2 = Round(A_Index / 2)
{ do things
}
}

The line elseif A_Index / 2 = Round(A_Index / 2)
is wrong but what ?
gregster
Posts: 9023
Joined: 30 Sep 2013, 06:48

Re: odd or even

11 Feb 2019, 08:54

Try

Code: Select all

arr := ["hello", "world", "test", "Autohotkey" ]

loop % arr.Count()		; Count() needs AHK v1.1.29+
{ 
	if (mod(A_index, 2) != 0)
		msgbox % "odd " A_index " : " arr[A_index]
	else
		msgbox % "even " A_index " : " arr[A_index]
}
btw, else if are two words in AHK, not elseif.
Last edited by gregster on 11 Feb 2019, 08:57, edited 1 time in total.
User avatar
sinkfaze
Posts: 616
Joined: 01 Oct 2013, 08:01

Re: odd or even

11 Feb 2019, 08:57

Code: Select all

For i, data in arrDataFile
{
	if	!Mod(i,2)
	{
		; do things
	}
}
:?:
digidings
Posts: 24
Joined: 22 Jan 2018, 17:04

Re: odd or even

11 Feb 2019, 08:59

Code: Select all

arr := ["hello", "world", "test", "Autohotkey" ]

loop % arr.Count()
{
	if (A_index & 1) ; Check LSB: if set it's odd
		msgbox % "odd " A_index " : " arr[A_index]
	else
		msgbox % "even " A_index " : " arr[A_index]
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Ineedhelplz, Spawnova and 236 guests