Free Online Flashcard Deck

05. Iteration and Loops Free Online FlashCards

Study 05. Iteration and Loops with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.

12 cards
01
Front

What is iteration?

Back

Iteration is the repeated execution of a block of instructions.

02
Front

What three ideas does a loop normally contain?

Back

Initialization establishes the starting state, the condition determines whether another iteration occurs, and the update changes state so the loop can eventually finish.

03
Front

When can a while loop execute zero times?

Back

A while loop checks its Boolean condition before each iteration, so its body may execute zero times.

04
Front

When is a for loop useful?

Back

A for loop is commonly used to visit each item in an iterable, such as a list, string, or range of numbers.

05
Front

What values does range(5) produce?

Back

The stop value is excluded. Therefore, range(5) produces 0, 1, 2, 3, and 4.

06
Front

What is a counter?

Back

A counter records how many times an event occurs. It commonly starts at zero and increases only when the event is observed.

07
Front

What is an accumulator?

Back

An accumulator combines values gradually to produce a result, such as a sum, product, maximum, string, or list.

08
Front

How should an accumulator be initialized?

Back

Initialize an accumulator with the identity value for its operation: 0 for a sum, 1 for a product, an empty string for concatenation, or an empty list for collection.

09
Front

What is a sentinel value?

Back

A sentinel is a special value that signals the end of input and is not treated as ordinary data.

10
Front

How many times does a 3-by-4 nested loop body execute?

Back

The inner loop completes all its iterations for every iteration of the outer loop. With 3 outer and 4 inner iterations, the body executes 12 times.

11
Front

What does break do?

Back

break immediately terminates the nearest enclosing loop.

12
Front

What does continue do?

Back

continue skips the remainder of the current iteration and moves to the next iteration.