Courseiva
Controlling Program FloweasyMultiple ChoiceObjective-mapped

1Z0-829 Controlling Program Flow Practice Question

How many times does the following loop execute? int i=0; while(i<5) { System.out.println(i); i++; }

⚠ Common exam trap

The trap here is that candidates often miscount the iterations by starting at 1 instead of 0, or forget that the condition is checked before each execution, leading them to choose 4 or 6 instead of the correct 5.

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

5

The loop starts with i=0, checks the condition i<5 (true), prints i, then increments i. This repeats until i becomes 5, at which point i<5 is false and the loop terminates. Thus, the loop executes exactly 5 times (i=0,1,2,3,4).

Answer analysis

Option-by-option breakdown

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

  • 0

    Why it's wrong here

    The condition i<5 is initially true, so the loop executes.

  • 6

    Why it's wrong here

    The loop stops when i becomes 5, so it runs 5 times.

  • 5

    Why this is correct

    The loop runs for i=0 through i=4, which is 5 iterations.

  • 4

    Why it's wrong here

    The loop runs 5 times, not 4.

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.