๐Ÿ“– Crammy ยท All study guides
AP Computer Science A ยท Unit 4

Loops: every key term you need

11 flashcard terms for AP Computer Science A Unit 4, written to match the course framework. Study them here, then drill them as interactive flashcards โ€” free, no account needed.

Study this unit free โ†’
Loops: Purpose
Repeat code multiple times; reduces duplication. Three types: while, for, enhanced for. Choice depends on situation.
While Loop
while (condition) { statements }. Repeats while condition true. Condition checked before each iteration. Can loop 0+ times.
Do-While Loop
do { statements } while (condition);. Executes body at least once, then checks condition. Rare in practice.
For Loop
for (init; condition; update) { statements }. Typical: for (int i=0; i<n; i++) { }. Combines initialization, condition, update.
Enhanced For Loop
for (type element : collection) { }. Iterates over array/ArrayList without index. Cleaner when order not critical.
Loop Control: break
Exits loop immediately. Used in while loops or when condition complex. Often in switch statements too.
Loop Control: continue
Skips rest of iteration, goes to next. Example: skip negative numbers in processing.
Nested Loops
Loop inside loop; careful with complexity (nยฒ iterations). Example: print multiplication table (rows, columns).
Loop Design Patterns
Accumulator: sum/count values. Sentinel: loop until special value. Flag: check if condition met. Max/min: track largest/smallest.
Infinite Loops
Condition always true; runs forever. Usually mistake but sometimes intentional. Break to exit.
Unit 4 Summary
Loops repeat code. While: condition-based. For: count-based (typically). Enhanced for: iterate collections cleanly.
Turn these into flashcards & quizzes โ†’

More AP Computer Science A guides