What is iteration?
Iteration is the repeated execution of a block of instructions.
Study 05. Iteration and Loops with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
What is iteration?
Iteration is the repeated execution of a block of instructions.
What three ideas does a loop normally contain?
Initialization establishes the starting state, the condition determines whether another iteration occurs, and the update changes state so the loop can eventually finish.
When can a while loop execute zero times?
A while loop checks its Boolean condition before each iteration, so its body may execute zero times.
When is a for loop useful?
A for loop is commonly used to visit each item in an iterable, such as a list, string, or range of numbers.
What values does range(5) produce?
The stop value is excluded. Therefore, range(5) produces 0, 1, 2, 3, and 4.
What is a counter?
A counter records how many times an event occurs. It commonly starts at zero and increases only when the event is observed.
What is an accumulator?
An accumulator combines values gradually to produce a result, such as a sum, product, maximum, string, or list.
How should an accumulator be initialized?
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.
What is a sentinel value?
A sentinel is a special value that signals the end of input and is not treated as ordinary data.
How many times does a 3-by-4 nested loop body execute?
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.
What does break do?
break immediately terminates the nearest enclosing loop.
What does continue do?
continue skips the remainder of the current iteration and moves to the next iteration.