IT - Iteration Overview

APCompSci_OverviewBanner.png

Iteration

Introduction

Imagine you must write a program which performs a repetitive task such as printing 1 to 100. Coding 100 lines to do this would be mundane. This is where loops come into the picture. Loops are specifically designed to perform repetitive tasks with one set of code. The purpose of loop statements is to repeat Java statements many times. In this module you will learn several different kinds of loop statements. You will learn how to implement them and under what conditions their use would be appropriate.

Key Terms

boolean condition - A mathematical equation where the result is a boolean.

definite loops - A loop where you know the exact number of iterations prior to entering the loop.

increment - The amount to change your variable by after each pass through a loop. Also known as step expression.

indefinite loops - A loop where the number of iterations is unknown.

infinite loop - A sequence in a computer program which loops endlessly.

initializer - The assignment of a starting value of a variable.

iteration - The repetition of a process within a computer program.

nested for loop - The placement of one for loop inside the body of another for loop.

sentinel value - A value whose presence guarantees termination of a loop.

Module Lessons Preview

In this module, we will study the following topics:

while Loops: A while loop is an indefinite loop which can iterate an undetermined number of times. It will iterate if the boolean condition is true. A sentinel value is used to stop the loop. 

for Loops: A for loop is a definite loop. The number of iterations is known before the loop is executed. It has an in initializing value, a boolean condition, and an incrementor.

Nested Iteration: When a loop is placed within another loop it is called nested iteration. Nested iteration typically is done with for loops. The inner loop completes all iterations for each one iteration of the outer loop.

APCompSci_OverviewBottom.png  IMAGES CREATED BY GAVS