Quick Syntax Question

 

So some syntax in an EA from the code base I didnt understand:

      for(i=0;i<K;i++) 
         if(i%2==0)

What does the "%" inside the if-statement mean??

 

% = modulus, remainder at division: so what remains if you divide by 2 in this case.

Seems the author was trying to get all even "i"s.

I wonder though, could he have done if(!(i%2))...?

 
I wonder though, could he have done if(!(i%2))...?
Yes, he could have. ;)
 
Or simply
for(i=0;i<K;i+=2) 
 
/me feels stupid right now :)))))
 
awesome. Thank you for that explanation, make complete sense now. as a matter of fact, I contrived some seriously ad-hoc code to get all even numbers for more own purposes some time ago..if only I had known :)