Courseiva
Control Flow and LoopshardMultiple ChoiceObjective-mapped

1Z0-811 Control Flow and Loops Practice Question

Exhibit

Refer to the exhibit.

public class NestedLoop {
    public static void main(String[] args) {
        outer:
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (i == 1 && j == 1) {
                    break outer;
                }
                System.out.println(i + "," + j);
            }
        }
    }
}

What is printed by the program?

```java

for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 3; j++) {

System.out.print(i + "," + j + " ");

if (i == 1) break;
    }
}

```

⚠ Common exam trap

A common mix-up: candidates assume both loops run to completion without considering that a `break` statement (or a conditional early exit) may terminate the inner loop prematurely, leading them to select Option D or C instead of recognizing the truncated output.

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

0,0 0,1 0,2 1,0

The program uses nested for loops. The outer loop runs with i from 0 to 1 (inclusive). For each i, the inner loop runs with j from 0 to 2 (inclusive). However, the inner loop contains a break statement that executes when i equals 1, causing the inner loop to terminate after printing the first pair for i=1 (1,0). Thus, the output is: 0,0 0,1 0,2 1,0. The outer loop then increments i to 2, but the condition i < 2 fails, so the program ends.

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,0 0,1 0,2 1,0

    Why this is correct

    The program's output results from the precise control flow achieved by a labelled `break` statement. The outer loop iterates, and for `i=0`, the inner loop executes completely, printing "0,0 0,1 0,2". When `i` becomes `1` and `j` is `0`, the program prints "1,0" and then encounters a `break` statement targeting the *outer* loop label. This immediately terminates both loops, satisfying the constraint for early exit from nested iterations.

  • 0,0 0,1 0,2

    Why it's wrong here

    This would occur if break outer were placed differently.

  • 0,0 0,1 0,2 1,0 1,1 1,2 2,0 2,1 2,2

    Why it's wrong here

    That would happen without the break.

  • 0,0 0,1 0,2 1,0 1,1

    Why it's wrong here

    Break outer stops after i=1,j=1, so only 1,0 is printed before break.

About these practice questions

This 1Z0-811 question is part of Courseiva's 481-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-811 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-811 exam.