Free Online Flashcard Deck

05 Loops and Repetition Free Online FlashCards

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

12 cards
01
Front

What is a loop?

Back

A loop repeats a block of instructions. It is useful for processing many values, repeating actions, or examining combinations of data.

02
Front

What four parts does a loop normally have?

Back

Initialization establishes the starting state, the condition determines whether to continue, the body performs repeated work, and progress updates the state toward stopping.

03
Front

When is a while loop appropriate?

Back

A while loop repeats as long as its condition is true. It is appropriate when the number of repetitions depends on input or changing state.

04
Front

When is a for loop usually the clearest choice?

Back

A for loop processes each item in a sequence or iterable. It is usually clearest for handling every item in a collection.

05
Front

What values does range(5) produce?

Back

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

06
Front

Why use enumerate() in a for loop?

Back

enumerate() supplies both an item’s position and its value, avoiding the need to maintain an index manually.

07
Front

What is a counter?

Back

A counter records how many times an event occurs. It is commonly initialized to zero and increased only when the event’s condition is satisfied.

08
Front

What is an accumulator?

Back

An accumulator combines many values into one result. Initialize it with the identity value: 0 for addition or 1 for multiplication.

09
Front

What does break do?

Back

break immediately terminates the innermost for or while loop. It is useful when the desired result has been found or further work is unnecessary.

10
Front

What does continue do?

Back

continue skips the rest of the current iteration and begins the next one. In a while loop, skipping an essential update can cause nontermination.

11
Front

When does Python’s loop else clause run?

Back

A loop else clause runs when the loop finishes normally, but not when break ends it. This supports searches where else reports that no match was found.

12
Front

What is a nested loop?

Back

A nested loop is a loop inside another loop. The inner loop completes all its iterations for each iteration of the outer loop.