Performance difference in for loop condition?
Posted
by CSharperWithJava
on Stack Overflow
See other posts from Stack Overflow
or by CSharperWithJava
Published on 2009-07-07T21:13:09Z
Indexed on
2010/05/18
2:00 UTC
Read the original article
Hit count: 266
Hello all, I have a simple question that I am posing mostly for my curiousity.
What are the differences between these two lines of code? (in C++)
for(int i = 0; i < N, N > 0; i++)
for(int i = 0; i < N && N > 0; i++)
The selection of the conditions is completely arbitrary, I'm just interested in the differences between , and &&.
I'm not a beginner to coding by any means, but I've never bothered with the comma operator.
Are there performance/behavior differences or is it purely aesthetic?
One last note, I know there are bigger performance fish to fry than a conditional operator, but I'm just curious. Indulge me.
Edit Thanks for your answers.
It turns out the code that prompted this question had misused the comma operator in the way I've described. I wondered what the difference was and why it wasn't a && operator, but it was just written incorrectly. I didn't think anything was wrong with it because it worked just fine. Thanks for straightening me out.
© Stack Overflow or respective owner