Introduction: Repetition Continued
We begin with this chapter's prerequisite, learning objectives, and overview
We'll cover the following...
We'll cover the following...
Prerequisite
Objectives
After completing this chapter, you should be able to:
- Write a
forloop or adoloop for a specific situation - Transform a
forloop into awhileloop - Identify logical errors in a given
fofloop ordoloop - Write nested
forloops ordoloops
Overview
The while statement that we introduced in the previous chapter controls the repetition of any group of Java statements. Although we do not need any other way to control a loop, Java provides two other statements for this purpose. When a loop is controlled by counting, the for statement provides a convenient alternative to the while statement. And if we know that the body of a loop will execute at least once, we can use a do statement instead of a while statement. This chapter discusses both of these alternative loop-control statements.