Jump to content
  • Advertisement
Sign in to follow this  
Sammy0037

nested if statements

This topic is 4844 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi a simple question: Does using three nested 'if' staments incur less overhead than having all three conditions in one? Several simple tests I ran seem to suggest the former. But maybe thats just an unfounded observation ;o) cheers

Share this post


Link to post
Share on other sites
Advertisement
Assuming C++ (and other languages with short circuit evaluation) and assuming that you are using non overloaded versions of || or && to combine conditions, then there should be no difference in the nested if statements and the three conditions in one. Of course, you might be doing something extra funky (like overloading &&) that could make that statement false.

Share this post


Link to post
Share on other sites
Nothing funky. It was just one of those things I was curious about as I was writing them up... "is there really a difference". The tests were simply a counter inside one the two possibilities. Keep track of how long it takes to reach a certain number. Run each many many times. And see if there is a pattern. Shorter times tended most of the time to lean towards broken up conditions. Im using VC++6 and maybe another one of those oddities on the list of things it does that arent the norm.

Or maybe not ;o)

Cheers

Share this post


Link to post
Share on other sites
Probably not. I recall short-circuiting working just fine in VC6. The nature of short-circuit evaluation, in fact, is such that it's actually somewhat easier to implement it than to not implement it; you can just stick a conditional jump after each test, instead of accumulating the boolean result somewhere.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!