Courseiva

1Z0-811 · domain

Control Flow and Loops

Practise Oracle Java Foundations 1Z0-811 Control Flow and Loops practice questions — original exam-style scenarios with answer choices, explanations, and analysis of common mistakes.

49 questions13 easy19 medium17 hard

Focused practice

Practice Control Flow and Loops questions

Scored sessions drawing only from this domain — pick a length below.

Start 20-question practice test →

What this domain covers

What to know about Control Flow and Loops

Control Flow and Loops questions test whether you can apply the concept in context, not just recognise a definition.

How the topic appears in realistic exam-style scenarios.

Which detail in the question changes the correct answer.

How to eliminate plausible but wrong options.

How to connect the question back to the wider exam objective.

Watch out for

Common Control Flow and Loops exam traps

  • Answering from memory before reading the full scenario.
  • Missing a constraint such as cost, availability, security, scope or command context.
  • Choosing a broad answer when the question asks for the most specific fix.
  • Ignoring why the wrong options are tempting.

Question index

All Control Flow and Loops questions (49)

Click any question to see the full explanation, or start a practice session above.

1

A developer needs to implement a menu-driven program that repeatedly displays options, reads input, and processes the choice until the user selects 'Exit'. Which loop structure and control flow is most appropriate?

Hard
2

Which TWO statements about the enhanced for loop (for-each) are correct?

Hard
3

In a Java method, a developer needs to skip the current iteration and move to the next when a certain condition is met inside a for loop. Which statement should be used?

Easy
4

A program needs to read user input until 'quit' is entered. Which loop ensures that the condition is evaluated after executing the body at least once?

Medium
5

Which two statements about the break statement in Java are true?

Easy
6

You are tuning a real-time data processing application that reads sensor data from a queue. The system must process each sensor reading, but occasionally a reading is invalid (null) and should be skipped. The loop must run indefinitely until the application is shut down gracefully. The current implementation uses a while(true) loop with a break condition when a shutdown flag is set. However, the loop is consuming excessive CPU because it continuously polls the queue even when no data is available. You need to modify the loop to reduce CPU usage while still processing data efficiently. Which approach should you take?

Hard
7

A developer writes a switch statement that checks the day of the week. The code uses fall-through to handle weekdays. What happens if a case does not end with a break?

Easy
8

What is the output of the following code? int i = 0; while (i < 5) { if (i == 3) { i++; continue; } System.out.print(i + " "); i++; }

Medium
9

Which of the following scenarios demonstrates the most appropriate use of a continue statement?

Hard
10

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; } } ```

Hard
11

Which two control flow statements can be used to terminate a loop prematurely?

Easy
12

Which loop is guaranteed to execute its body at least once?

Easy
13

int count = 0; for (int i = 0; i < 5; i++) { if (i == 2) { continue; } count++; } System.out.println(count); What is the output of the program?

Easy
14

A developer writes the following code: for (int i = 0; i < 5; i++) { for (int j = i; j < 5; j++) { System.out.print(j); } } How many times does the inner loop execute in total?

Hard
15

A developer receives a ticket that a batch processing job is running indefinitely. The job reads records from a database and processes them in a loop. The code uses a while(true) loop with a break condition when a sentinel value is encountered. However, due to a data anomaly, the sentinel value is never reached, causing the loop to run forever. The developer needs to fix the loop to prevent infinite execution while still allowing processing of all records until the sentinel is reached. Which approach is most appropriate?

Medium
16

Which TWO are best practices for using control flow statements? (Choose two.)

Hard
17

Given the code fragment: ```java int[] data = {1, 2, 3, 4, 5}; int sum = 0; for (int i = 0; i <= data.length; i++) { sum += data[i]; } System.out.println(sum); ``` What is the result?

Medium
18

A programmer writes a switch statement to handle different cases. The code compiles and runs, but the output is unexpected: 'A' prints when the input is 'B'. Which is the most likely cause?

Medium
19

A programmer wants to iterate over a list of strings and print each that starts with 'A'. Which loop construct is best suited?

Easy
20

A developer is writing a method to find the first occurrence of a negative number in an array and return its index, or -1 if none found. The current implementation uses a for loop with an if condition and a return when found. However, the method throws a NullPointerException when the array is null. The developer wants to handle this edge case gracefully and still return -1. Which approach is most appropriate?

Medium
21

Which THREE are valid loop constructs in Java? (Choose three.)

Medium
22

Arrange the steps to define a class with a main method in Java in the correct order.

Medium
23

Which THREE statements are true about the switch statement in Java? (Choose three.)

Medium
24

What is the output of the code? ```java for (int i = 0; i < 5; i++) { if (i == 2) { continue; } System.out.print(i + " "); } ```

Medium
25

Which THREE statements are true about the break and continue statements in Java? (Choose three.)

Hard
26

A novice developer wrote a condition: if (x = 10) { ... } What is the result?

Medium
27

Which three statements about the switch statement in Java are true?

Hard
28

Which TWO of the following are valid loop constructs in Java? (Choose two.)

Easy
29

Which TWO statements are true about the switch statement in Java? (Choose two.)

Easy
30

A developer is troubleshooting a performance issue in a reporting application. A nested loop iterates over a large dataset: the outer loop processes each row, and the inner loop performs a complex computation on each column. The application is taking longer than expected. Upon reviewing the code, the developer notices that the inner loop's termination condition is recalculated each iteration, which involves a costly method call. Which optimization should the developer implement to improve performance?

Hard
31

Which THREE of the following are valid loop constructs in Java?

Easy
32

A junior developer wrote a while loop that never terminates. What is the most likely cause?

Medium
33

A developer needs to iterate over a 2D array row by row and exit early if a specific value is found in any cell. Which nested loop structure with control statements is most efficient?

Hard
34

Match each Java operator to its description.

Medium
35

A developer writes: for(int i=0; i<10; i++) { if(i%2==0) continue; System.out.print(i); }. What is the output?

Hard
36

Consider a method that processes a two-dimensional array (matrix). It uses nested for loops. The inner loop uses a label 'outer' to break out of the outer loop. Under what condition is this label beneficial?

Hard
37

A team is implementing a search algorithm that iterates over an array of integers. The loop should stop as soon as the target value is found. Which loop construct is most appropriate?

Medium
38

Which loop best suits a scenario where the number of iterations is unknown and depends on user input?

Medium
39

Refer to the exhibit. What is the output?

Medium
40

A developer writes the following code: if (score >= 90) { grade = 'A'; } else if (score >= 80) { grade = 'B'; } else if (score >= 70) { grade = 'C'; } else { grade = 'D'; } What is the value of grade if score is 75?

Easy
41

What is the value of sum printed? int sum = 0; for (int i = 0; i < 3; i++) { sum = sum + i; } System.out.println(sum);

Hard
42

Which THREE of the following are valid types that can be used as a switch expression in Java (as of Java 8)?

Medium
43

A company's application uses a switch statement to handle different user roles. The code currently has a bug where after processing one role, it unintentionally executes the next role's logic. Which concept is being misused?

Medium
44

A developer implements a loop that processes a list of transactions. The loop must ensure that at least one transaction is processed even if the list is empty. Which loop construct guarantees this?

Hard
45

A developer is writing a batch processing application that reads a list of orders and processes each one. The orders are stored in an array of Order objects. The processing logic is complex and involves multiple conditional checks. The developer uses a for-each loop to iterate over the array. However, during testing, the application throws an IndexOutOfBoundsException when processing orders that have a status of "CANCELLED". The developer wants to skip the processing of cancelled orders but still record that the order was skipped in a log. The current code is: for (Order order : orders) { if (order.getStatus().equals("CANCELLED")) { // Skip } // process order process(order); log(order); } The developer considers four options: A. Change the for-each loop to a traditional for loop with an index and increment only when order is not cancelled. B. Add a continue statement inside the if block. C. Change the if condition to check for non-cancelled orders and wrap only the process(order) call inside the if block, leaving log(order) outside. D. Use a while loop with an iterator and remove cancelled orders from the array. Which option best solves the problem without modifying the array and while still logging all orders?

Hard
46

A developer needs to iterate over an array of integers and compute the sum of its elements. Which loop construct is most appropriate for this task?

Easy
47

In a nested loop structure, a developer wants to exit completely from the outer loop when a certain condition is met inside the inner loop. Which approach is correct?

Hard
48

What is the output of the program?

Medium
49

A developer writes a loop that iterates over an array of integers. The loop should stop when it encounters a negative number. Which control flow construct best achieves this?

Easy

Frequently asked questions

What does the Control Flow and Loops domain cover on the 1Z0-811 exam?
Control Flow and Loops questions test whether you can apply the concept in context, not just recognise a definition.
How many questions are in this domain?
This page lists all 49 Control Flow and Loops questions in the 1Z0-811 question bank. The actual exam draws from this domain proportionally to its weighting in the official exam blueprint.
What is the best way to practise this domain?
Start with a short focused session (10 questions) to identify gaps, then work through explanations. Repeat with a longer session once the weak areas feel solid.
Can I practise only Control Flow and Loops questions?
Yes — the session launcher on this page filters questions to this domain only. Choose any session length for inline explanations and scoring.
oracle-java-foundations ORACLE-JAVA-FOUNDATIONS java control flow loops Practice Questions