Check for even or odd numbers in loop

Hello,

I would like to check in the beginning of a loop if the current i value is even or odd. If i is even, the loop should continue, otherwise it should go to the next step. So here is a simple example:

For(i=0; i<numFilesSelected; i+=1)
    If(i = even )  // how do I express this correctly?

    ...

    Else
    Endif
Endfor


Since I'm a beginner in programming with Igor (and in general) I have no idea how to realize this.
Thank you for any help!
I'm not sure which is faster, but you could use either of the following to test for evenness:

if (!(i & 1))
if (mod(i, 2) == 0)
if (!mod(i, 2))
I would do:

Function test()
variable ii = 0
for(ii = 0 ; ii < numberoffilesselected ; ii +=1)
    switch(mod(ii, 2))
        case 0:
                    //continue will go to the next iteration
                    continue
        break
        case 1:
        break
    endswitch
endfor
End


I think in C that switches are faster than "if"s, but I can't be sure.
andyfaff wrote:
I would do:

Function test()
variable ii = 0
for(ii = 0 ; ii < numberoffilesselected ; ii +=1)
    switch(mod(ii, 2))
        case 0:
                    //continue will go to the next iteration
                    continue
        break
        case 1:
        break
    endswitch
endfor
End


I think in C that switches are faster than "if"s, but I can't be sure.


That may be true if you are comparing a switch statement with many options to an if...else if...endif ladder because the compiler can optimize the switch statement better than the if...else if...endif ladder, but in this particular case there are only two possibilities so I'm not sure that there is any room for optimization. Plus, Igor code isn't optimized anyway.