tailieunhanh - Lecture Practical C++ programming - Chapter 6: Decision and control statements

Student are now introduced to the fact that computers cannot only do computitions, but can also make decisions. Decision statements for the most part are fairly straight-forward and fairly simple, as are the relation operators. A conditional statement works on the single statement that follows it. This chapter will introduce "Decision and control statements" in C, inviting you refer. | Chapter - 6 Decision and Control Statements Practical C Programming Copyright 2003 O Reilly and Associates Page1 What are decision and control statements We ve been working on linear programs. That is we start the program and execute each s tatement in a straight line until we reach the end. Decision and control statements allow us to change the flow of the program. Branching statements cause one section of code to be executed or not depending on a conditional clause. Looping statements allow a section of code to be repeated a number of times or until a condition occurs. Practical C Programming Copyright 2003 O Reilly and Associates Page2 if Statement General form if condition statement If the condition is true non-zero the statement is executed. If the condition is false zero the statement is not executed. Example if total_owed 0 std cout You owe nothing. n Practical C Programming Copyright 2003 O Reilly and Associates .