Check for even or odd numbers in loop
boonerino
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
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!
October 18, 2011 at 06:38 am - Permalink
if (mod(i, 2) == 0)
if (!mod(i, 2))
October 18, 2011 at 06:45 am - Permalink
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.
October 18, 2011 at 07:33 pm - Permalink
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.
October 19, 2011 at 06:58 am - Permalink