Java Reference
In-Depth Information
C HAPTER S UMMARY
1.
There are three types of repetition statements: the while loop, the do-while loop, and
the for loop .
2. The part of the loop that contains the statements to be repeated is called the loop body.
3. A one-time execution of a loop body is referred to as an iteration of the loop.
4. An infinite loop is a loop statement that executes infinitely.
5. In designing loops, you need to consider both the loop control structure and the loop
body.
6.
The while loop checks the loop-continuation-condition first. If the condition
is true , the loop body is executed; if it is false , the loop terminates.
7.
The do-while loop is similar to the while loop, except that the do-while loop exe-
cutes the loop body first and then checks the loop-continuation-condition to
decide whether to continue or to terminate.
8.
The while loop and the do-while loop often are used when the number of repetitions
is not predetermined.
9. A sentinel value is a special value that signifies the end of the loop.
10. The for loop generally is used to execute a loop body a fixed number of times.
11. The for loop control has three parts. The first part is an initial action that often ini-
tializes a control variable. The second part, the loop-continuation-condition ,
determines whether the loop body is to be executed. The third part is executed after
each iteration and is often used to adjust the control variable. Usually, the loop control
variables are initialized and changed in the control structure.
12. The while loop and for loop are called pretest loops because the continuation condi-
tion is checked before the loop body is executed.
13. The do-while loop is called a posttest loop because the condition is checked after the
loop body is executed.
14.
Two keywords, break and continue , can be used in a loop.
15.
The break keyword immediately ends the innermost loop, which contains the break.
16.
The continue keyword only ends the current iteration.
Q UIZ
Answer the quiz for this chapter online at www.cs.armstrong.edu/liang/intro10e/quiz.html .
P ROGRAMMING E XERCISES
Pedagogical Note
Read each problem several times until you understand it. Think how to solve the prob-
lem before starting to write code. Translate your logic into a program.
A problem often can be solved in many different ways. Students are encouraged to
explore various solutions.
read and think before coding
explore solutions
 
 
Search WWH ::




Custom Search