ABSTRACT

In the previous chapter, we showed how to use the if and switch statements in order to choose from several possible program execution paths. In this chapter, we present different types of flow control structures that are called loop structures. These structures allow the same code segment to be executed multiple times. There are three loop structures in Java: while, do, and for. The while structure allows us to repeatedly execute the same block of code until a condition is met. The do structure is similar, but it guarantees that the code will be executed at least once. The for structure is best suited when we know how many times we want to execute a particular code segment. The chapter also covers the modulus operator.