Courseiva
Controlling Program FlowmediumMultiple ChoiceObjective-mapped

1Z0-829 do-while loop Practice Question

Consider the following do-while loop:

```java

int x = 10;

do { x--;

} while (x < 10);

System.out.println(x); ```

What is printed?

⚠ Common exam trap

Candidates often assume that the loop will eventually stop when x reaches some value, but the condition x < 10 is always true after the first iteration because x is decreasing from 10. This leads to an infinite loop. For OCP, always trace the loop carefully, especially when the condition compares a decreasing variable to a constant.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

3

The do-while loop executes the body first (x--), then checks the condition x < 10. After the first iteration, x becomes 9, and the condition (9 < 10) is true. As x continues to decrease, it will always be less than 10, so the condition remains true forever. This results in an infinite loop; the program never reaches the print statement. Therefore, no output is produced, and none of the options (3, 2, 1) are correct.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • 3

    Why this is correct

    Incorrect. The loop does not terminate, so no value is printed. This answer mistakenly assumes the loop stops when x becomes 3.

  • The loop does not compile because x is not declared final.

    Why it's wrong here

    Incorrect. The variable x does not need to be final; the code compiles. The loop runs indefinitely.

  • 2

    Why it's wrong here

    Incorrect. The loop never terminates, so 2 is never printed.

  • 1

    Why it's wrong here

    Incorrect. The loop never terminates, so 1 is never printed.

About these practice questions

This 1Z0-829 question is part of Courseiva's 513-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 1Z0-829 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-829 exam.