Tino APCS

Iterations

Lesson Overview: Solving problems on a computer very often requires a repetition of a block of code. Reading in data from a file, outputting to a file or adding numbers are situations where repetition is required. In Lesson A9, Recursion, we have already explored repeating code. However, not all iterative problems lend themselves to recursive solutions. Java provides three alternative constructs for repeating code with the for loop, the while loop, and the do-while loop. The while and for control structures allow us to set up a conditional loop, one that occurs for an indefinite period of time until some condition becomes false. We will also study the optional do-while loop and the concept of nested loops.

Lesson Vocab
break

A keyword used to move to the end of a loop's execution.

BOUNDARY

The limits of where a loop executes code.

do-while

An exit check loop with one operand.

ENTRY CHECK

A loop type that checks the condition before ever executing a statement.

EXIT CHECK

A type of loop that checks the condition after executing its statements at least once.

for

A type of loop typically used when the exact number of iterations is known in advance.

LOOP INVARIANT

An assertion about a loop that is relevant to the purpose of the loop.

NESTED LOOP

When one or more loops are placed inside of another loop.

SENTINEL

A fake value used to identify when a loop should end.

STATE

The current value of a given variable.

while

An entry check loop with only one operand.