< previous page page_130 next page >

Page 130
Q&A
Q How do you choose between ifelse and switch?
A If there are more than just one or two else clauses, and all are testing the same value, consider using a switch statement.
Q How do you choose between while and dowhile?
A If the body of the loop should always execute at least once, consider a dowhile loop; otherwise try to use the while loop.
Q How do you choose between while and for?
A 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.
Q Is it better to use while(1) or for(;;)?
A There is no significant difference.

 
< previous page page_130 next page >

If you like this book, buy it!