while Loops

AP Computer Science A· difficulty 3/5

int i = 10;
do {
  System.out.println(i);
  i++;
} while (i < 5);
System.out.println("done");

What is printed?

  • A

    nothing

  • B

    10 11 done

  • C

    done

  • D

    10 done

    check_circle

Explanation

do-while always executes the body at least once. It prints 10, increments to 11, then checks 11 < 5 (false), exits. Then "done" prints.

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

Related questions