ABSTRACT

In Chapter 2, you have studied the control structure sequence. In Chapter 4, you have seen the control structure selection. In this chapter, you will study the control structure repetition. A program with sequence structure alone is capable of executing one statement aft er another in sequence. Such a program has no ability to make decisions. With the introduction of selection structure, programs became capable of making decisions based on data values. For example, using sequence structure alone it is possible to write a program to compute the cumulative test score by adding fi ve test scores. If you want to translate the cumulative test score into letter grades, you need a control structure that can examine and make decisions based on the test score. Suppose you want to fi nd the class average of a test. If the class consists of only a handful of students, you can defi nitely use the sequence structure to fi nd the average. However, such a technique is not practical if there are 75 students. What you need is a structure capable of repeating an action. To fi nd the sum of the test scores of all students in a class, you need a control structure that can read a number and add the number read to a partial sum repeatedly. Such a structure is called a repetition structure. In this chapter, you will learn about various repetition structures available

• • • •

• • • • •

in Java. However, the fundamental principles you learn in this chapter can be applied in many scripting languages and programming languages including C, C++, and C#.