Chapter 2 Control Structures 1. A procedure for solving a problem in terms of the actions to be executed and the order in which these actions should be executed is called an algorithm. 2. Declarations are messages to compiler telling it the name, value, and attributes of a variable (identifier) and request the compiler to reserve memory space for it. 3. The 7 categories of statements are: 1. declaration 2. arithmetic and logical expressions 3. selection 4. iteration(repetition) 5. sequential 6.input/output 7. exception handling 4. Whenever there are more than one statements is to be executed where normally only a single statement is expected (accoding to grammar), these statements must be enclosed in braces forming a compound statement. A compound statement can be placed anywhere a single statement can be placed. 5. An empty statement indicating that no actions is to be taken is indicated by placing a semicolon(;) where a statement would normally be. 6. A repetition structure specifies that an action is to be repeated while some conditions remain true. 7. The break statement, when executed in one of the repetition structure (for, while, and do/while), cause immediate exit from the structure. 8. The continue statement, when executed in one of the repetition structure (for, while, and do/while), skip the rest of the remaining statements in the structure and proceed with the the next iteration of the loop. 9. The switch statement handles a series of decisions in which a particular integer or integer expression is tested for values it may assume, and different actions are taken. It is necessary to include a break statement after the statements for each case. Several cases can execute the same statements by listing the case labels together before the statements. 10. Placing a semicolon after the if test, for, while statment is a common error to skip the test or loop body. 11. An attempt to divide by zero or use NULL pointer is an error. 12. Use two commas instead of two semicolons in the for statement is a common mistake. 13. Misuse = to test the equality is a common error. 14. Do not compare floating point numbers for equality or inequality, test the absolute value of the difference within a specified samll value. 15. Unary operator should be place immediately next to the operand with no intervening spaces. 16. Initialize the variables when declared avoid the uninitialized variables. 17. Type a pair of braces and then insert the statement can prevent missing the closing brace. 19. Declare each variable in a seperating line with comments. 20. Leave a space after if, while, and for keywords. 21. Use <= or >= instead of < or > can avoid off by one problems. 22. Provide the default case in the switch statement. The break is unnecessary in the default case. 23. In performance-oriented programs, try to use the smallest integer size which is proper for the application. 24. The programmer (designer) terminates the top-down, stepwise refinement process when the algorithm is specified in sufficient detail for the programmer to convert it into C++ directly.