Chapter 4 Control Structures: Part (Yahoo free web hosting) 1 153 Java
Chapter 4 Control Structures: Part 1 153 Java Keywords static throw void super throws volatile switch transient while synchronized this true try Keywords that are reserved, but not used, by Java const goto Fig. 4.2Fig. Java keywords (part 2 of 2). Common Programming Error 4.1 Using a keyword as an identifier is a syntax error. Well, that is all there is. Java has only seven control structures: the sequence structure, three types of selection structures and three types of repetition structures. Each program is formed by combining as many of each type of control structure as is appropriate for the algorithm the program implements. As with the sequence structure in Fig. 4.1, we will see that each control structure is flowcharted with two small circle symbols, one at the entry point to the control structure and one at the exit point. Single-entry/single-exit control structures make it easy to build programs; the control structures are attached to one another by connecting the exit point of one control structure to the entry point of the next. This procedure is similar to the way in which a child stacks building blocks, so we call it control-structure stacking. We will learn that there is only one other way in which control structures may be connected: control-structure nesting. Thus, algorithms in Java programs are constructed from only seven different types of control structures, combined in only two ways. 4.5 The ifSelection Structure A selection structure is used to choose among alternative courses of action in a program. For example, suppose that the passing grade on an examination is 60 (out of 100). Then the pseudocode statement If student s grade is greater than or equal to 60 Print Passed determines if the condition student s grade is greater than or equal to 60 is true or false. If the condition is true, then Passed is printed, and the next pseudocode statement in order is performed. (Remember that pseudocode is not a real programming language.) If the condition is false, the Print statement is ignored, and the next pseudocode statement in order is performed. Note that the second line of this selection structure is indented. Such indentation is optional, but it is highly recommended, because it emphasizes the inherent structure of structured programs. The Java compiler ignores white-space characters, like blanks, tabs and newlines, used for indentation and vertical spacing. Programmers insert these white-space characters to enhance program clarity. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/2/01