PrepGo

AP Computer Science Principles Flashcards: Iteration

Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026

Review key ideas with interactive flashcards. This set includes 16 cards to help you master important concepts.

How do iteration statements affect the sequential flow of control in an algorithm?
Iteration statements change the default sequential flow by causing a set of statements to be repeated, rather than being executed only once in order.
Card 1 of 16

All Flashcards (16)

How do iteration statements affect the sequential flow of control in an algorithm?
Iteration statements change the default sequential flow by causing a set of statements to be repeated, rather than being executed only once in order.
What happens in a `REPEAT UNTIL(condition)` loop if the condition is true before the loop begins?
If the condition evaluates to true initially, the loop body is not executed at all because the condition is checked before the first iteration.
Describe the `REPEAT UNTIL(condition)` iteration structure.
The `REPEAT UNTIL(condition)` structure is a type of iteration where a block of statements is repeated until its Boolean expression 'condition' evaluates to true.
An algorithm needs to ask a user for a password until they enter the correct one. Which iteration structure from the exam reference sheet is best for this task?
The `REPEAT UNTIL(condition)` structure is best, where the condition would be 'password is correct', as the loop needs to run an unknown number of times.
What are the two main ways an iteration can be controlled to stop repeating?
An iteration can repeat a specified number of times or it can repeat until a given Boolean condition is met.
Describe the `REPEAT n TIMES` iteration structure.
The `REPEAT n TIMES` structure is a type of iteration where a specific block of statements is executed exactly 'n' times.
What is iteration?
Iteration is a repeating portion of an algorithm that continues for a specified number of times or until a given condition is met.
What are iteration statements?
Iteration statements are constructs that change the sequential flow of control by repeating a set of statements zero or more times until a stopping condition is met.
Determine the result of the following statement: `REPEAT 3 TIMES { DISPLAY("Loop") }`
The statement will display the word "Loop" three times, as the block of statements is executed the specified number of times.
Is it possible for the body of a `REPEAT UNTIL(condition)` loop to execute zero times?
Yes, if the Boolean condition evaluates to true before the first iteration, the loop body will be skipped and not executed at all.
What are the two key skills related to iteration mentioned in the course framework?
The two key skills are the ability to express an algorithm that uses iteration and the ability to determine the result or side effect of iteration statements.
What is the result of this code? `score <- 100; REPEAT UNTIL(score >= 100) { score <- score + 10 }`
The loop body is not executed at all. The condition `score >= 100` is true initially, so the loop terminates immediately.
You need to write an algorithm to process exactly 50 contest entries. Which iteration structure from the exam reference sheet is most appropriate?
The `REPEAT n TIMES` structure is most appropriate, as it is designed to execute a block of code a specified number of times (in this case, 50).
In a `REPEAT UNTIL(condition)` loop, what is an infinite loop?
An infinite loop occurs in a `REPEAT UNTIL(condition)` structure when the ending condition will never evaluate to true, causing the loop to repeat forever.
Without using a programming language, express an algorithm for washing five dishes using iteration.
An algorithm could be: Repeat 5 times { Pick up a dirty dish. Wash the dish. Place the dish in the drying rack. }
What is the result of this code? `count <- 0; REPEAT UNTIL(count < 0) { count <- count + 1 }`
This code results in an infinite loop. The variable 'count' starts at 0 and only increases, so the condition `count < 0` will never become true.