Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
This module discusses the statements that control a program’s flow of execution. There are three categories of : selection statements, which include the if and the switch; iteration statements, which include the for, while, and do-while loops; and jump statements, which include break, continue, return, and goto. Except for return, which is discussed later in this book, the remaining control statements, including the if and for statements to which you have already had a brief introduction, are examined here. . | Module3 Program Control Statements Table of Contents CRITICAL SKILL 3.1 The if Statement.2 CRITICAL SKILL 3.2 The switch Statement.7 CRITICAL SKILL 3.3 The for Loop.13 CRITICAL SKILL 3.4 The while Loop.19 CRITICAL SKILL 3.5 The do-while Loop.21 CRITICAL SKILL 3.6 Using break to Exit a Loop.27 CRITICAL SKILL 3.7 Using continue.29 CRITICAL SKILL 3.8 Nested Loops.34 CRITICAL SKILL 3.9 Using the goto Statement.35 This module discusses the statements that control a program s flow of execution. There are three categories of selection statements which include the if and the switch iteration statements which include the for while and do-while loops and jump statements which include break continue return and goto. Except for return which is discussed later in this book the remaining control statements including the if and for statements to which you have already had a brief introduction are examined here. 1 C A Beginner s Guide by Herbert Schildt CRITICAL SKILL 3.1 The if Statement Module 1 introduced the if statement. Now it is time to examine it in detail. The complete form of the if statement is expression statement else statement where the targets of the if and else are single statements. The else clause is optional. The targets of both the if and else can also be blocks of statements. The general form of the if using blocks of statements is if expression statement sequence else statement sequence If the conditional expression is true the target of the if will be executed otherwise the target of the else if it exists will be executed. At no time will both be executed. The conditional expression controlling the if may be any type of valid C expression that produces a true or false result. The following program demonstrates the if by playing a simple version of the guess the magic number game. The program generates a random number prompts for your guess and prints the message Right if you guess the magic number. This program also introduces another C library function .