Courseiva
Controlling Program FlowmediumMultiple ChoiceObjective-mapped

1Z0-829 Controlling Program Flow Practice Question

A method uses an enhanced for loop to iterate over a list of strings and prints each string. The code is:

```java List<String> list = List.of("A", "B", "C");

for (String s : list) {
    if (s.equals("B")) {

break;

}

System.out.print(s);

}

```

What is the result?

⚠ Common exam trap

Many exam-takers think the break statement causes a ConcurrentModificationException or that it prints "AB" because they forget that break exits the loop before executing the print statement for the matched element.

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

A

The enhanced for loop iterates over the list, and when it encounters the string "B", the break statement immediately exits the loop. Therefore, only "A" is printed before the loop terminates. Option C is correct because the output is just "A".

Answer analysis

Option-by-option breakdown

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

  • The code throws a ConcurrentModificationException.

    Why it's wrong here

    The list is not modified during iteration.

  • ABC

    Why it's wrong here

    Break prevents printing B and C.

  • A

    Why this is correct

    Prints A, then breaks at B.

  • AB

    Why it's wrong here

    Break occurs before printing B.

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.