Section 6.1. Introduction


[Page 250]

6.1. Introduction

As we learned in Chapter 3, a control structure is a language element that changes the flow of control of a program. Thus far, we have used the if and if/else statements to select between two or more alternative paths in a program. We have used the while-loop structure to repeat statements. And we have used method-call-and-return to invoke methods that carry out certain well-defined tasks in a program.

In this chapter we will extend our repertoire of control structures. We will introduce the for and do-while statements, both of which are used in programs that require calculations to be repeated. We will also introduce the switch statement, which will give us another way, in addition to if/else, to select from among several alternative paths in a program.

We begin by introducing the idea of a counting loop, which is used for repetitive tasks when you know beforehand exactly how many repetitions are necessary. This type of loop is most often implemented using a for statement.

We then distinguish two kinds of conditional loops, which are used for performing repetitive tasks where the number of repetitions depends on a noncounting condition. These kinds of loops are usually implemented using Java's while and do-while statements. We give examples of several kinds of loop bounds and use them to identify several useful principles of loop design. Finally, we introduce some of the key principles of the structured programming approach, a disciplined design approach that preceded the object-oriented approach.




Java, Java, Java(c) Object-Orienting Problem Solving
Java, Java, Java, Object-Oriented Problem Solving (3rd Edition)
ISBN: 0131474340
EAN: 2147483647
Year: 2005
Pages: 275

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net