Chapter 5 - Repetition Structures

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/30

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 7:07 PM on 6/20/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

31 Terms

1
New cards

repetition structure

causes a statement or set of statements to execute repeatedly

2
New cards

condition-controlled loop

uses a true/false condition to control the number of times that it repeats

3
New cards

count-controlled loop

repeats a specific number of times

4
New cards

while loop

consists of a condition that is tested for a true or false value and a statement or set of statements that is repeated as long as the condition is true

5
New cards

What is the output for this code?

spam = 0

while spam < 5:
	print("Hello, World.")
	spam = spam + 1

Hello, World.

Hello, World.

Hello, World.

Hello, World.

Hello, World.

6
New cards

pretest loop

a loop that tests its conditions before performing an iteration

ex: while loops

7
New cards

True or false: loops don’t need a way to terminate

false

8
New cards

infinite loops

loops that continue to repeat until the program is interrupted

  • usually occur when the programmer forgets to write code inside the loop that makes the condition false

9
New cards

for loop

used to iterate over a sequence and execute a block of code for each item in that sequence

10
New cards

target variable

the variable that is used in the for clause; it is the target of an assignment at the beginning of each loop iteration

11
New cards

What is the output of this code?

fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
	print(fruit)

apple

banana

cherry

12
New cards

True or false: the values that appear in a list do not have to be a consecutively ordered series of numbers

true

13
New cards

range()

generates a sequence of integers within a specified range

14
New cards

range() syntax

range(start, stop, step)

  • start and step are optional

15
New cards

Which part of the range() function is inclusive?

start

16
New cards

Which part of the range() function is exclusive?

stop

17
New cards

What is the default for start in the range() function?

0

18
New cards

What is the default for step in the range() function?

1

19
New cards

How do you use decrements in the range() function?

by using a negative step value

20
New cards

What is the output for this code?

for n in range(0,5):
	print(n)

0

1

2

3

4

21
New cards

What is the purpose of the target variable in a for loop?

to reference each item in a sequence of items as the loop iterates

22
New cards

running total

a sum of numbers that accumulates with each iteration of a loop

23
New cards

accumulator

the variable used to keep the running total

24
New cards

What does the accumulator contain when the loop finishes?

the total of the numbers that were read by the loop

25
New cards

What happens if the accumulator starts with any value other than 0?

it will not contain the correct total when the loop finishes

26
New cards

sentinel

a special value that marks the end of a sequence of values

27
New cards

input validation

the process of inspecting data that has been input to a program, to make sure it is valid before it is used in a computation

28
New cards

nested loop

a loop inside another loop

29
New cards

How many times does the inner loop go through all its iterations?

for every single iteration of an outer loop

30
New cards

True or false: inner loops complete their iterations faster than outer loops

true

31
New cards

How do you get the total number of iterations for a nested loop?

multiply the number of iterations of all the loops