|
Repetition and Looping
An Introduction with Examples in Java |
|
Prof. David Bernstein
|
| Computer Science Department |
| bernstdh@jmu.edu |
while Loops (cont.)
while Loops (cont.)
An Example with 0 Iterations
javaexamples/basics/WhileExample1.java (Fragment: 1)while Loops (cont.)
An Example of an Infinite while Loop
while Loops (cont.)
An Example of an Indefinite while Loop
do-while Loops (cont.)
do-while Loops (cont.)
do-while Loop
for Loops (cont.)
for Loops (cont.)
for loops
for (j=0; j<50; ++j)
for (int i=0; i<50; ++i)
i and j
j can be accessed outside of the
loop, i can't
age = age + 1;)age += 1;)
for)
or indefinite (prefer while or
do-while)?do-while)?