Web hosting compare - 152 Control Structures: Part 1 Chapter 4 Consider

152 Control Structures: Part 1 Chapter 4 Consider the flowchart segment for the sequence structure in Fig. 4.1. We use the rectangle symbol, also called the action symbol, to indicate any type of action, including a calculation or an input/output operation. The flowlines in the figure indicate the order in which the actions are to be performed; first, grade is to be added to total, and then 1 is to be added to counter. Java allows us to have as many actions as we want in a sequence structure. As we will soon see, anywhere a single action may be placed, we may instead place several actions in sequence. When drawing a flowchart that represents a complete algorithm, an oval symbol containing the word Begin is the first symbol used in the flowchart; an oval symbol containing the word End indicates where the algorithm ends. When drawing only a portion of an algorithm, as in Fig. 4.1, the oval symbols are omitted in favor of small circle symbols, also called connector symbols. Perhaps the most important flowcharting symbol is the diamond symbol, also called the decision symbol, which indicates that a decision is to be made. We will discuss the diamond symbol in the next section. Java provides three types of selection structures; we discuss each in this chapter and in Chapter 5. The if selection structure either performs (selects) an action, if a condition is true, or skips the action, if the condition is false. The if/else selection structure performs an action if a condition is true and performs a different action if the condition is false. The switch selection structure (Chapter 5) performs one of many different actions, depending on the value of an expression. The if structure is called a single-selection structure, because it selects or ignores a single action (or, as we will soon see, a single group of actions). The if/else structure is called a double-selection structure, because it selects between two different actions (or groups of actions). The switchstructure is called a multiple-selection structure, because it selects among many different actions (or groups of actions). Java provides three types of repetition structures namely, while, do/while and for. (do/while and for are covered in Chapter 5.) Each of the words if, else, switch, while, do and for are Java keywords. These words are reserved by the language to implement various features, such as Java s control structures. Keywords cannot be used as identifiers, such as for variable names. A complete list of Java keywords is shown in Fig. 4.2. Java Keywords abstract boolean break byte case catch char class continue default do double else extends false final finally float for if implements import instanceof int interface long native new null package private protected public return short Fig. 4.2Java keywords (part 1 of 2). Fig. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/2/01

Leave a Reply