|
| < Day Day Up > |
|
Table 6-1 will come in handy when deciding when to use a particular C++ control statement:
| Control Statement | Use |
|---|---|
| if | ...for simple decision |
| if-else | ...for decision with alternative action |
| switch | ...in place of nested if-else statements where the condition is an integral or enumeration type |
| while | ...when condition must be tested first |
| do | ...when body must be executed at least once |
| for | ...to loop for a known amount of times |
| break | ...in case statement to prevent case statement fall- through; ...to terminate while, do-while, and for loops. |
| continue | ...to skip to the end of a while, do-while, or for loop. |
| goto | ...to perform unconditional jump to a labeled statement |
|
| < Day Day Up > |
|