Free Practice Quiz Question List

4 Loops and Repetition Online Quiz Questions

Use this free practice quiz with 20 questions to review 4 Loops and Repetition, test your knowledge, and prepare for your next test or exam.

20 questions
01
Choose one
1 point

A program uses a while loop whose condition is false before the first test. What happens to the loop body?

  1. A

    The body must execute exactly once.

  2. B

    The body may execute zero times.

  3. C

    The body executes at least twice.

  4. D

    The condition is checked only after the body.

02
Choose one
1 point

A menu must be displayed once before the program checks whether the user's choice is valid. Which loop form is most appropriate?

  1. A

    Use a for loop because all menu choices are numeric.

  2. B

    Use a while loop because it always executes once.

  3. C

    Use a do...while loop because the menu must be displayed before validation.

  4. D

    Use a nested loop because the menu may repeat.

03
Choose one
1 point

A program must print every value in the array colors, but it does not need the index. Which loop is the clearest choice?

  1. A

    for...of

  2. B

    for...in

  3. C

    An indexed for loop is always required.

  4. D

    A while loop with no condition

04
Choose all
1 point

Consider nested loops where row runs from 1 through 3 and column runs from 1 through 4. Select all statements that are correct.

  1. A

    The inner loop body runs 12 times.

  2. B

    The outer loop body runs 12 times.

  3. C

    The outer loop controls the rows.

  4. D

    The inner loop runs only once overall.

05
Choose all
1 point

Select all statements that correctly describe break and continue in loops.

  1. A

    break can stop the nearest enclosing loop.

  2. B

    continue exits every enclosing loop.

  3. C

    continue skips the remainder of the current iteration.

  4. D

    break only skips the current iteration and then always continues.

06
True or false
1 point

True or false: When an accumulator is used to calculate a sum, initializing it to 0 is generally appropriate.

  1. A

    True

  2. B

    False

07
True or false
1 point

True or false: This loop terminates after printing five values: let count = 0; while (count < 5) { console.log(count); }

  1. A

    True

  2. B

    False

08
Written response
1 point

In the array-search pattern described in the material, what numeric sentinel represents “not found” before or when a match is absent?

09
Written response
1 point

For let total = 0; for (let i = 1; i <= 4; i++) { total += i; }, what is the value of total after the loop finishes?

10
Fill in the blank
1 point

Complete the three-part loop design: establishes the starting state, determines whether another iteration occurs, and moves the loop toward termination.

11
Fill in the blank
1 point

A do...while loop checks its condition executing the body.

12
Open ended
1 point

Explain how to choose among for, for...of, while, and do...while loops. Include at least two practices that help make the chosen loop terminate correctly and handle boundary cases.

13
Choose one
1 point

What does for (let i = 0; i < values.length; i++) do when used to process an array named values?

  1. A

    It skips the first element.

  2. B

    It visits every valid array index exactly once.

  3. C

    It visits one index beyond the end.

  4. D

    It runs only when the array has at least two elements.

14
Choose one
1 point

Which loop form best fits this task: print the integers from 0 through 7 exactly once, with no input and no early exit?

  1. A

    Use a while loop because all repetition should be condition-controlled.

  2. B

    Use a for loop because the loop has a known range of eight values.

  3. C

    Use a do...while loop because its body must execute at least once.

  4. D

    Use a for...in loop because the values are numeric.

15
True or false
1 point

True or false: If a JavaScript while loop's condition is false before the first test, its body executes zero times.

  1. A

    True

  2. B

    False

16
Choose one
1 point

A program must ask for a menu choice at least once and repeat the prompt only when the choice is outside the range 1 through 3. Which loop is the best fit?

  1. A

    A for loop because it always runs once before testing its condition.

  2. B

    A while loop because it validates input before requesting it.

  3. C

    A do...while loop because the prompt occurs before validation.

  4. D

    A for...in loop because it iterates over the possible choices.

17
Written response
1 point

What is the final value of number after this JavaScript loop finishes? let number = 1; while (number < 10) { number *= 2; }

18
Choose one
1 point

In a loop that examines the integers from 1 through 20 and increments evenCount only when the current integer is even, which description is correct?

  1. A

    evenCount is a counter, while number is the loop-control variable.

  2. B

    number is an accumulator, while evenCount is the loop condition.

  3. C

    Both variables are accumulators because both change during the loop.

  4. D

    evenCount is the loop-control variable because it determines when the loop ends.

19
Written response
1 point

In the search pattern that initializes position to -1, what term describes the special value representing “not found”?

20
Choose one
1 point

How many total times does the inner loop body execute in this code? for (let row = 1; row <= 3; row++) { for (let column = 1; column <= 4; column++) { console.log(row, column); } }

  1. A

    4

  2. B

    7

  3. C

    10

  4. D

    12