cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Which line of code is better?
Which line of code is better?
Nov 28, 2016 at 5:50am UTC
cnewb31
(1)
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 UTC
Nov 28, 2016 at 6:26am UTC
JLBorges
(13770)
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.