AP® Computer Science A glossary

for loop

Course: AP® Computer Science A Shows up in: Unit 2: Selection and Iteration

An iterative statement whose header has three parts: the initialization (runs once), the Boolean expression (checked before each iteration) and the update (after each iteration).

Appears in the course and exam description (CED): 2.8.A.12.8.A.22.8.A.3

for (int i = a; i < b; i++) runs b - a times. Any for loop can be rewritten as an equivalent while loop, and the reverse.

int sum = 0;
for (int n = 2; n <= 10; n += 2) {
    sum += n;
}
System.out.println(sum);

Output:

30
Learn it properly, with a checkpoint 2.8 for Loops

Related terms

Was this page helpful?

No names are ever shown, and every public comment is checked by us first. Please do not include personal details. To get a reply, email [email protected].

↑ Top

Enlarged view of the selected figure