When does a `while` loop test its condition?
A `while` loop tests its condition before executing the body, so it may execute zero times.
Study 04 Loops and Iteration with 12 free online flashcards. Review key terms, definitions, and concepts with this interactive flashcard deck.
When does a `while` loop test its condition?
A `while` loop tests its condition before executing the body, so it may execute zero times.
What guarantees that a `do-while` body runs once?
A `do-while` loop executes its body first, then tests its condition, so the body runs at least once.
What three parts does a C++ `for` header combine?
A `for` header contains initialization, a condition, and an update expression.
What is the usual scope of a `for` initialization variable?
A variable declared in a `for` loop’s initialization normally has scope only within that loop.
What does `break` do inside nested loops?
`break` immediately terminates the innermost enclosing loop and continues with the first statement afterward.
What happens after `continue` in a `for` loop?
In a `for` loop, `continue` skips the rest of the body, then runs the update expression before testing the condition again.
Why can `continue` cause a `while` loop to become infinite?
In a `while` loop, update the condition’s control variable before `continue`; otherwise, the condition may never change and the loop may not terminate.
What is an accumulator used for?
An accumulator stores a running result; initialize it before the loop and update it during every relevant iteration.
What is a sentinel in input processing?
A sentinel is a special input value that signals the end of input and is usually not processed as ordinary data.
What is the purpose of a validation loop?
A validation loop repeatedly requests input until the value satisfies the required condition.
How many times does a nested grid body execute?
For a rectangular grid with `r` rows and `c` columns, the inner loop body executes r×c times.
What causes a loop to become infinite?
A loop can fail to terminate when its condition-control state never changes toward making the condition false.