Loops in Java
body of a loop
Statements to be repeated(in a while loop includes change)
for loop syntax
for ( initialization; loop condition; loop update ) { // loop body // goes here }
while
A for loop may always be written as a _____ loop.
loop
A way to repeat one or more statements in a program
9
How many times does the code snippet given below display "Loop Execution"? int i = 1; while (i != 10) { System.out.println ("Loop Execution"); i++; }
10
How many times will the following loop run? int i = 0; while (i < 10) { System.out.println(i); i++; }
nested loop
One loop inside of another
at least once
The do while loop executes the loop body ________
execute
The while loop might not_______ the loop body at all.
hand-tracing
Writing down a table of values of the variables and how they change each time the body of the loop executes (Helpful for the AP CS exam and in general)
all
break works for which loop types?
end
do while loop condition is evaluated at the ____ of the loop
++
increments by 1
do while loop syntax
int i = 0 do { // body of the loop goes here } while ( i < 4 ); system.out.println(i)
semi colon
putting a _______________ after the condition will cause the compiler to loop over an empty statement (do nothing each time through the loop)
break
will cause you to exit from the innermost loop
while loop syntax
• Example while (i < 10) { f = f * i; ++i; }