Free Practice Quiz Question List

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.

20 questions
01
Choose one
1 point

What happens when the condition of a while loop is initially false?

  1. A

    The body executes exactly once.

  2. B

    The body executes zero times.

  3. C

    The condition is ignored.

  4. D

    The body executes before the condition is tested.

02
Choose one
1 point

Which property most directly favors a do-while loop over a while loop?

  1. A

    The loop body must be allowed to execute at least once.

  2. B

    The loop body must never execute when the condition is initially false.

  3. C

    The loop must always use a break statement to terminate.

  4. D

    The loop must combine initialization, condition testing, and updating in one statement.

03
Choose one
1 point

What does this C++ loop print?

for (int value = 10; value >= 0; value -= 2) { std::cout << value << ' '; }

  1. A

    10 8 6 4 2 0

  2. B

    10 8 6 4 2

  3. C

    8 6 4 2 0

  4. D

    10 9 8 7 6 5 4 3 2 1 0

04
Choose all
1 point

Which elements should a loop design normally make explicit? Select all that apply.

  1. A

    An initial state

  2. B

    A continuation condition

  3. C

    A break statement in every iteration

  4. D

    A progress step

05
Choose all
1 point

Which statements correctly describe continue inside a C++ for loop? Select all that apply.

  1. A

    It skips the rest of the current iteration.

  2. B

    It runs the for update expression before the next condition test.

  3. C

    It exits every enclosing loop.

  4. D

    It affects only the nearest enclosing loop.

06
True or false
1 point

True or false: In nested C++ loops, a break statement inside the inner loop exits both the inner and outer loops.

  1. A

    True

  2. B

    False

07
True or false
1 point

True or false: In for (int& value : values), assigning to value can modify the corresponding element in values.

  1. A

    True

  2. B

    False

08
Written response
1 point

Which C++ loop statement should you use when a menu must be displayed at least once before the program checks whether to continue?

09
Written response
1 point

In while (std::cin >> value && value != -1), what numeric value signals the end of input?

10
Fill in the blank
1 point

Complete the comparison: A while loop tests its condition the body, whereas a do-while loop tests its condition the body.

11
Fill in the blank
1 point

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.

12
Open ended
1 point

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.

13
Choose one
1 point

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 << ") "; } }

  1. A

    7 times

  2. B

    9 times

  3. C

    12 times

  4. D

    16 times

14
Choose one
1 point

Which statement correctly describes a C++ while loop?

  1. A

    It always executes its body at least once.

  2. B

    It may execute its body zero times.

  3. C

    It can be used only with integer conditions.

  4. D

    It automatically increments the variable in its condition.

15
True or false
1 point

A C++ do-while loop executes its body at least once, even when its condition is initially false.

  1. A

    True

  2. B

    False

16
Written response
1 point

Which C++ loop statement is the best choice when input must be repeatedly validated and the number of attempts is not known in advance?

17
Written response
1 point

How many times does the body execute in for (int i = 0; i < 5; ++i) { ... }?

18
Choose one
1 point

In a C++ for loop, what normally happens immediately after the loop body finishes and before the next condition test?

  1. A

    The initialization expression runs again.

  2. B

    The condition is skipped once.

  3. C

    The update expression runs.

  4. D

    The loop variable is destroyed before the condition test.

19
Choose one
1 point

Which loop condition safely traverses every element of a zero-based array with size elements exactly once?

  1. A

    i < size

  2. B

    i <= size

  3. C

    i == size

  4. D

    i > size

20
Choose one
1 point

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?

  1. A

    It terminates the entire loop immediately.

  2. B

    It skips the remaining statements in the current iteration, then performs the update expression.

  3. C

    It restarts the current iteration without evaluating the condition.

  4. D

    It exits the nearest enclosing function.