Which line of code is better?

Nov 28, 2016 at 5:50am
Which code of line is better, and why?
 
if ((i + 1) % 3 == 0)

or
 
if (i == 2 || i == 5)

Last edited on Nov 28, 2016 at 5:51am
Nov 28, 2016 at 6:26am
The two are not equivalent, are they?

If i is guaranteed to be in [0,7], they are equivalent and
if (i == 2 || i == 5) is better (more readable, the intent is transparent).
Topic archived. No new replies allowed.