O'Reilly logo

Sams Teach Yourself C++ in 24 Hours, Third Edition by Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Q&A

Q1:How do you choose between if...else and switch?
A1: If there are more than just one or two else clauses, and all are testing the same value, consider using a switch statement.
Q2:How do you choose between while and do...while?
A2: If the body of the loop should always execute at least once, consider a do...while loop; otherwise try to use the while loop.
Q3:How do you choose between while and for?
A3: If you are initializing a counting variable, testing that variable and incrementing it each time through the loop, consider the for loop. If your variable is already initialized and is not incremented on each loop, a while loop might be the better choice.
Q4:Is it better to use while(1) or for(;;)?
A4: There is no significant difference.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required