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 ?
odd or even
Re: odd or even
Try
btw, else if are two words in AHK, not elseif.
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]
}
Last edited by gregster on 11 Feb 2019, 08:57, edited 1 time in total.
Re: odd or even
Code: Select all
For i, data in arrDataFile
{
if !Mod(i,2)
{
; do things
}
}
Re: odd or even
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]
}
Who is online
Users browsing this forum: Google [Bot], Ineedhelplz, Spawnova and 236 guests