AP Computer Science Principles Flashcards: Iteration

Study Iteration in AP Computer Science Principles with focused flashcards that help you recognize the idea, recall the key rule, and apply it in practice-style prompts.

AP Computer Science Principles

Iteration

0 mastered0 still learning

0% Complete

QUESTION
1/ 76

In a 'for' loop, what does the loop variable do?

Tap card or press Space to flip

ANSWER

The loop variable iterates through a sequence. It takes on each value from the sequence being looped over.

How well did you know it?

Card 1 / 76

What this deck covers

This deck focuses on Iteration, giving you a quick way to review the definitions, rules, and examples that matter most for AP Computer Science Principles.

How to use these flashcards

Work through these flashcards in short sessions. Try to answer each prompt before flipping the card, then revisit any cards you miss until the explanation feels automatic.

All flashcards

Flashcard 1: In a 'for' loop, what does the loop variable do?

Answer: The loop variable iterates through a sequence. It takes on each value from the sequence being looped over.

Flashcard 2: What happens when 'continue' is executed in a loop?

Answer: Skips the current iteration and continues with the next. It jumps directly to the next loop iteration.

Flashcard 3: Describe 'break' in the context of loops.

Answer: 'Break' exits the loop immediately. It terminates the loop completely.

Flashcard 4: Find the error: for i in [1,2,3]: print(i)

Answer: No error; it prints 1, 2, 3. The syntax correctly iterates over the list.

Flashcard 5: What is the role of an iterator?

Answer: An iterator provides access to elements in a collection. It enables sequential access to data structures.

Flashcard 6: What will 'while False: print('Hello')' output?

Answer: Outputs nothing. False condition prevents any loop execution.

Flashcard 7: Find the error: for i in range(1,5): print(i)

Answer: No error; it prints numbers 1 to 4. The syntax is correct and executes properly.

Flashcard 8: Identify the purpose of 'range()' in a 'for' loop.

Answer: 'range()' specifies the start, stop, and step of iteration. It generates a sequence of numbers for iteration.

Flashcard 9: What is the output of 'for i in range(2): print('Hi')'?

Answer: Prints 'Hi' twice. The loop executes twice with range(2).

Flashcard 10: What is the role of an iterator?

Answer: An iterator provides access to elements in a collection. It enables sequential access to data structures.

Flashcard 11: Which Python statement exits a loop prematurely?

Answer: The 'break' statement exits a loop prematurely. It immediately terminates the loop regardless of condition.

Flashcard 12: Choose the correct syntax for a 'while' loop in Python.

Answer: 'while condition:'. This is the proper Python while loop syntax.

Flashcard 13: What is the output of 'for i in range(4, 1, -1): print(i)'?

Answer: Prints 4, 3, 2. Negative step counts down from 4 to 2.

Flashcard 14: What loop structure is used for counting iterations?

Answer: A 'for' loop is used for counting iterations. It provides precise iteration control.

Flashcard 15: Find the error: while True print('Hello')

Answer: Error: Missing colon after 'True'. Python requires a colon after the condition.

Flashcard 16: Identify the purpose of 'range()' in a 'for' loop.

Answer: 'range()' specifies the start, stop, and step of iteration. It generates a sequence of numbers for iteration.

Flashcard 17: Which loop structure is best for iterating a known number of times?

Answer: A 'for' loop is best for iterating a known number of times. It allows precise control over the number of iterations.

Flashcard 18: What is the output of range(5, 1, -1)?

Answer: Outputs 5, 4, 3, 2. Negative step creates descending sequence.

Flashcard 19: What is the function of 'pass' in a loop?

Answer: 'pass' acts as a placeholder and does nothing. It prevents syntax errors in empty code blocks.

Flashcard 20: What is a nested loop?

Answer: A loop inside another loop. Creates multiple levels of iteration depth.

Flashcard 21: Identify an example of an iterable in Python.

Answer: Lists are examples of iterables. Lists can be looped through using for loops.

Flashcard 22: Determine the loop type: Iterates with a known count.

Answer: A 'for' loop iterates with a known count. The iteration count is predetermined.

Flashcard 23: What does 'for i in range(0,5,2)' iterate over?

Answer: Iterates over 0, 2, 4. The step parameter of 2 skips every other number.

Flashcard 24: What is the output of range(5, 1, -1)?

Answer: Outputs 5, 4, 3, 2. Negative step creates descending sequence.

Flashcard 25: Identify the loop structure that continues until a condition is false.

Answer: A 'while' loop continues until a condition is false. It evaluates the condition before each iteration.

Flashcard 26: Correct the error: for i in 0..5: print(i)

Answer: Use 'range(0, 5)' instead of '0..5'. Python uses range() function instead of .. notation.

Flashcard 27: Write a loop that prints numbers 1 to 5.

Answer: for i in range(1, 6): print(i). This creates a sequence from 1 to 5 inclusive.

Flashcard 28: Which Python statement exits a loop prematurely?

Answer: The 'break' statement exits a loop prematurely. It immediately terminates the loop regardless of condition.

Flashcard 29: Determine the loop type: Iterates with a known count.

Answer: A 'for' loop iterates with a known count. The iteration count is predetermined.

Flashcard 30: What type of loop would you use for indefinite iteration?

Answer: A 'while' loop is used for indefinite iteration. The condition determines when to stop iterating.

Flashcard 31: Identify the loop that allows iteration over elements of a list.

Answer: 'for element in list:' allows iteration over list elements. This syntax directly accesses each list element.

Flashcard 32: What is iteration in computer programming?

Answer: Iteration is the repetition of a block of code multiple times. It's a fundamental programming concept for repeating tasks.

Flashcard 33: Which loop structure is used for iterating over a sequence?

Answer: A 'for' loop is used for iterating over a sequence. It processes each element in the sequence.

Flashcard 34: What does 'for i in range(0,5,2)' iterate over?

Answer: Iterates over 0, 2, 4. The step parameter of 2 skips every other number.

Flashcard 35: Which loop structure is used for iterating over a sequence?

Answer: A 'for' loop is used for iterating over a sequence. It processes each element in the sequence.

Flashcard 36: What is a key characteristic of a 'while' loop?

Answer: Continues as long as the condition is true. It evaluates the condition before each iteration.

Flashcard 37: What keyword starts a 'while' loop in Python?

Answer: The 'while' keyword starts a 'while' loop. It's the standard syntax for conditional loops in Python.

Flashcard 38: Identify the loop that allows iteration over elements of a list.

Answer: 'for element in list:' allows iteration over list elements. This syntax directly accesses each list element.

Flashcard 39: What will 'while False: print('Hello')' output?

Answer: Outputs nothing. False condition prevents any loop execution.

Flashcard 40: What happens when 'continue' is executed in a loop?

Answer: Skips the current iteration and continues with the next. It jumps directly to the next loop iteration.

Flashcard 41: Identify an example of an iterable in Python.

Answer: Lists are examples of iterables. Lists can be looped through using for loops.

Flashcard 42: What keyword starts a 'while' loop in Python?

Answer: The 'while' keyword starts a 'while' loop. It's the standard syntax for conditional loops in Python.

Flashcard 43: What is the output of 'for i in range(4, 1, -1): print(i)'?

Answer: Prints 4, 3, 2. Negative step counts down from 4 to 2.

Flashcard 44: In a 'for' loop, what does the loop variable do?

Answer: The loop variable iterates through a sequence. It takes on each value from the sequence being looped over.

Flashcard 45: What is a common use of iteration in programming?

Answer: Iterating through lists or arrays. It's essential for processing data collections efficiently.

Flashcard 46: What is an infinite loop?

Answer: An infinite loop runs indefinitely without terminating. Usually occurs when the termination condition is never met.

Flashcard 47: Describe 'break' in the context of loops.

Answer: 'Break' exits the loop immediately. It terminates the loop completely.

Flashcard 48: Which loop structure is best for iterating a known number of times?

Answer: A 'for' loop is best for iterating a known number of times. It allows precise control over the number of iterations.

Flashcard 49: What does the 'continue' statement do in a loop?

Answer: The 'continue' statement skips to the next iteration. It bypasses remaining code in the current iteration.

Flashcard 50: Identify the loop structure that continues until a condition is false.

Answer: A 'while' loop continues until a condition is false. It evaluates the condition before each iteration.

Flashcard 51: Find the error: for i in [1,2,3]: print(i)

Answer: No error; it prints 1, 2, 3. The syntax correctly iterates over the list.

Flashcard 52: Write a loop that prints numbers 1 to 5.

Answer: for i in range(1, 6): print(i). This creates a sequence from 1 to 5 inclusive.

Flashcard 53: What type of loop would you use for indefinite iteration?

Answer: A 'while' loop is used for indefinite iteration. The condition determines when to stop iterating.

Flashcard 54: What is a key characteristic of a 'while' loop?

Answer: Continues as long as the condition is true. It evaluates the condition before each iteration.

Flashcard 55: Find the error: while True print('Hello')

Answer: Error: Missing colon after 'True'. Python requires a colon after the condition.

Flashcard 56: What does the 'continue' statement do in a loop?

Answer: The 'continue' statement skips to the next iteration. It bypasses remaining code in the current iteration.

Flashcard 57: What is a loop iteration?

Answer: One complete execution of the loop body. It represents one cycle through the loop body.

Flashcard 58: Correct the error: for i in 0..5: print(i)

Answer: Use 'range(0, 5)' instead of '0..5'. Python uses range() function instead of .. notation.

Flashcard 59: What is the output of 'for i in range(2): print('Hi')'?

Answer: Prints 'Hi' twice. The loop executes twice with range(2).

Flashcard 60: What is the function of 'pass' in a loop?

Answer: 'pass' acts as a placeholder and does nothing. It prevents syntax errors in empty code blocks.

Flashcard 61: What is a common use of iteration in programming?

Answer: Iterating through lists or arrays. It's essential for processing data collections efficiently.

Flashcard 62: Find the error: for i in range(3): print(i)

Answer: No error; it prints 0, 1, 2. The syntax is valid and executes correctly.

Flashcard 63: What is iteration in computer programming?

Answer: Iteration is the repetition of a block of code multiple times. It's a fundamental programming concept for repeating tasks.

Flashcard 64: What is an infinite loop?

Answer: An infinite loop runs indefinitely without terminating. Usually occurs when the termination condition is never met.

Flashcard 65: What is a nested loop?

Answer: A loop inside another loop. Creates multiple levels of iteration depth.

Flashcard 66: Find the error: for i in range(3): print(i)

Answer: No error; it prints 0, 1, 2. The syntax is valid and executes correctly.

Flashcard 67: What is the benefit of using 'range()' in loops?

Answer: 'range()' provides a sequence of numbers to iterate over. It generates sequences without manual counting.

Flashcard 68: What does 'for i in range(3)' do?

Answer: Iterates with values 0, 1, 2. Single argument creates sequence from 0 to n-1.

Flashcard 69: Identify a common loop structure in programming.

Answer: A 'for' loop is a common loop structure. It iterates over sequences or a specified range.

Flashcard 70: What is the benefit of using 'range()' in loops?

Answer: 'range()' provides a sequence of numbers to iterate over. It generates sequences without manual counting.

Flashcard 71: Find the error: for i in range(1,5): print(i)

Answer: No error; it prints numbers 1 to 4. The syntax is correct and executes properly.

Flashcard 72: Choose the correct syntax for a 'while' loop in Python.

Answer: 'while condition:'. This is the proper Python while loop syntax.

Flashcard 73: What loop structure is used for counting iterations?

Answer: A 'for' loop is used for counting iterations. It provides precise iteration control.

Flashcard 74: What does 'for i in range(3)' do?

Answer: Iterates with values 0, 1, 2. Single argument creates sequence from 0 to n-1.

Flashcard 75: What is a loop iteration?

Answer: One complete execution of the loop body. It represents one cycle through the loop body.

Flashcard 76: Identify a common loop structure in programming.

Answer: A 'for' loop is a common loop structure. It iterates over sequences or a specified range.