while Loops

AP Computer Science A· difficulty 3/5

do {
    System.out.println(i);
    i++;
} while (i < 0);

Which loop is equivalent in behavior when i starts at 5?

  • A

    An infinite loop

  • B

    No iterations occur

  • C

    System.out.println(5); i = 6; (loop runs exactly once)

    check_circle
  • D

    Loop runs five times

Explanation

A do-while runs at least once and only repeats while the condition is true. Starting at 5 the body runs once, prints 5, increments to 6, and 6 < 0 is false.

Want 10 more like this — adaptive to your weak spots?

Related questions