What happens when the condition of a while loop is initially false?
4 Repetition and Looping Online Quiz Questions
Use this free practice quiz with 20 questions to review 4 Repetition and Looping, test your knowledge, and prepare for your next test or exam.
Which property most directly favors a do-while loop over a while loop?
- A
The loop body must be allowed to execute at least once.
- B
The loop body must never execute when the condition is initially false.
- C
The loop must always use a break statement to terminate.
- D
The loop must combine initialization, condition testing, and updating in one statement.
What does this C++ loop print?
for (int value = 10; value >= 0; value -= 2) { std::cout << value << ' '; }
- A
10 8 6 4 2 0 - B
10 8 6 4 2 - C
8 6 4 2 0 - D
10 9 8 7 6 5 4 3 2 1 0
Which elements should a loop design normally make explicit? Select all that apply.
- A
An initial state
- B
A continuation condition
- C
A
breakstatement in every iteration - D
A progress step
Which statements correctly describe continue inside a C++ for loop? Select all that apply.
- A
It skips the rest of the current iteration.
- B
It runs the
forupdate expression before the next condition test. - C
It exits every enclosing loop.
- D
It affects only the nearest enclosing loop.
True or false: In nested C++ loops, a break statement inside the inner loop exits both the inner and outer loops.
- A
True
- B
False
True or false: In for (int& value : values), assigning to value can modify the corresponding element in values.
- A
True
- B
False
Which C++ loop statement should you use when a menu must be displayed at least once before the program checks whether to continue?
In while (std::cin >> value && value != -1), what numeric value signals the end of input?
Complete the comparison: A while loop tests its condition the body, whereas a do-while loop tests its condition the body.
Complete both recommendations: To traverse a zero-based array by index safely, use the condition . In a range-based loop, use a when the loop must modify the original elements.
Consider this C++ code:
int count = 1;
while (count <= 5) {
std::cout << count << '\n';
}
Explain the loop's error and provide a corrected version or a precise correction that makes it terminate after printing the intended sequence.
How many times does the innermost output statement execute?
for (int row = 1; row <= 3; ++row) {
for (int column = 1; column <= 4; ++column) {
std::cout << '(' << row << ',' << column << ") ";
}
}
- A
7 times
- B
9 times
- C
12 times
- D
16 times
Which statement correctly describes a C++ while loop?
- A
It always executes its body at least once.
- B
It may execute its body zero times.
- C
It can be used only with integer conditions.
- D
It automatically increments the variable in its condition.
A C++ do-while loop executes its body at least once, even when its condition is initially false.
- A
True
- B
False
Which C++ loop statement is the best choice when input must be repeatedly validated and the number of attempts is not known in advance?
How many times does the body execute in for (int i = 0; i < 5; ++i) { ... }?
In a C++ for loop, what normally happens immediately after the loop body finishes and before the next condition test?
- A
The initialization expression runs again.
- B
The condition is skipped once.
- C
The update expression runs.
- D
The loop variable is destroyed before the condition test.
Which loop condition safely traverses every element of a zero-based array with size elements exactly once?
- A
i < size - B
i <= size - C
i == size - D
i > size
Consider for (int i = 1; i <= 10; ++i) { if (i % 2 == 0) { continue; } std::cout << i << ' '; }. What is the effect of continue when i is even?
- A
It terminates the entire loop immediately.
- B
It skips the remaining statements in the current iteration, then performs the update expression.
- C
It restarts the current iteration without evaluating the condition.
- D
It exits the nearest enclosing function.