for Loops

AP Computer Science A· difficulty 2/5

int i = 0;
while (i < 10) {
    System.out.println(i);
}

What problem does this loop have?

  • A

    It prints 0 through 9

  • B

    It prints 1 through 10

  • C

    Infinite loop; i is never incremented

    check_circle
  • D

    Compile error: missing braces

Explanation

Without i++ inside the loop body, the condition i < 10 is always true, so the loop runs forever printing 0.

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

Related questions