Candidates must trace Java control flow precisely and select the right branching statement for a scenario. The most important thing is to know exactly when break, continue, and return transfer control, and to predict loop iteration counts without relying on fall-through assumptions.
Start practicing
Control Flow and Loops — choose a session length
Free · No account required
Domain overview
This domain covers Java control flow: if/else, switch statements (including String and enum), and the for, while, and do-while loops. It also tests break and continue with and without labels, and how return exits a method. Questions require predicting exact output or choosing the correct branching statement for a given scenario.
Exam objectives
Evaluating if/else if/else chains and ternary expressions for exact branch selection
Writing switch statements on String, int, char, and enum values with default and fall-through
Using for, while, and do-while loops, including loop variable scope and termination conditions
Applying break, continue, and labeled break/continue to control nested loop execution
Forgetting that switch fall-through executes all later case labels until a break or the end of the switch.
Assuming continue exits the loop; it only skips the rest of the current iteration and proceeds to the update/condition.
Mixing up do-while (body runs at least once) with while (condition checked before the first iteration).
Click any question to see the full explanation and answer options, or start a focused practice session above.
Which loop is guaranteed to execute its body at least once?
2What is the output of the following code? int i = 0; while (i < 5) { if (i == 3) { i++; continue; } System.out.print(i + " "); i++; }
3A developer writes: for(int i=0; i<10; i++) { if(i%2==0) continue; System.out.print(i); }. What is the output?
4Which loop best suits a scenario where the number of iterations is unknown and depends on user input?
5Which THREE statements are true about the switch statement in Java? (Choose three.)
6Which THREE statements are true about the break and continue statements in Java? (Choose three.)
7What is the output of the code? ```java for (int i = 0; i < 5; i++) { if (i == 2) { continue; } System.out.print(i + " "); } ```
8What is the value of sum printed? int sum = 0; for (int i = 0; i < 3; i++) { sum = sum + i; } System.out.println(sum);
9You 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?
10Match each Java operator to its description.
11A 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?
12A 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?
13In 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?
14Which THREE of the following are valid loop constructs in Java?
15int 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?
16What 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; } } ```
17A 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?
18A 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?
19Consider 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?
20A 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?
21A 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?
22A 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?
23A programmer wants to iterate over a list of strings and print each that starts with 'A'. Which loop construct is best suited?
24A novice developer wrote a condition: if (x = 10) { ... } What is the result?
25Which of the following scenarios demonstrates the most appropriate use of a continue statement?
26Which TWO statements are true about the switch statement in Java? (Choose two.)
27Which THREE are valid loop constructs in Java? (Choose three.)
28Which TWO are best practices for using control flow statements? (Choose two.)
29A 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?
30A 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?
31A 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?
32In 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?
33A junior developer wrote a while loop that never terminates. What is the most likely cause?
34A 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?
35Which two statements about the break statement in Java are true?
36Given 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?
37A 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?
38A 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?
39A developer writes the following method to search a sorted int array for a target value: ```java public static int search(int[] arr, int target) { int lo = 0, hi = arr.length - 1; while (lo <= hi) { int mid = (lo + hi) / 2; if (arr[mid] == target) { return mid; } else if (arr[mid] < target) { lo = mid; } else { hi = mid; } } return -1; } ``` When the method is called with a target that exists in the array, the method sometimes never returns. Which change fixes the defect?
40A developer is writing a utility that must print each character of a String on its own line. The code is: ```java String word = "Java"; for (int i = 0; i <= word.length(); i++) { System.out.println(word.charAt(i)); } ``` When run, the program prints the four characters correctly but then throws an exception. What is the cause and the correct fix?
41A developer is writing a method that prints the numbers 1 through 5. The method must stop printing as soon as the number 3 has been printed, without printing any further numbers. Which loop control statement should be used inside the loop body when the current value equals 3?
42A developer is writing a Java method that must return the smallest even number in an int array. If no even number exists, the method must return -1. The developer writes: public static int firstEven(int[] nums) { for (int i = 0; i < nums.length; i++) { if (nums[i] % 2 == 0) { return nums[i]; } } return -1; } Which statement describes the behavior of this method?
43A developer needs to iterate over an array of department names and print each one. The array may contain null entries, and the code must handle a null entry by printing the text "unknown" instead of causing a NullPointerException. Which loop construct is most appropriate for iterating over the array while still allowing a null check before each element is used?
44A developer writes the following method to classify a character: public static String classify(char c) { switch (c) { case 'a': case 'e': case 'i': case 'o': case 'u': return "vowel"; case 'y': return "sometimes"; default: return "consonant"; } } What is printed by System.out.println(classify('e'));?
45A developer is writing a Java program that must print the numbers 1 through 10, but only even numbers should be printed. The developer writes: for (int i = 1; i <= 10; i++) { if (i % 2 != 0) { continue; } System.out.print(i + " "); } What is the output?
46A developer writes the following method to print all even numbers from 0 up to and including a supplied limit: ```java void printEvens(int limit) { int n = 0; do { System.out.print(n + " "); n += 2; } while (n <= limit); } ``` When the method is called as `printEvens(0)`, what is printed, and why?
47A developer needs a loop that executes its body at least once, then repeats only while a boolean condition remains true. Which loop construct should the developer choose?
48A developer needs to iterate over a two-dimensional array of daily temperatures and stop processing entirely as soon as a temperature above 100 is encountered, without processing any remaining rows. The developer writes code using nested for loops. Which statement about using break inside the inner loop is correct for this requirement?
49A developer is reviewing a method that uses a labeled break statement inside nested loops. Which two statements about labeled break are true? (Choose two.)
50A developer writes the following code: int i = 0; while (i < 3) { System.out.print(i + " "); i++; } What is printed?
51A developer writes a for loop to process an array of temperatures. The loop must skip any temperature that is below zero and continue processing the remaining temperatures. Which change to the loop body correctly implements this requirement?
52A developer writes the following method: public static void countDown(int start) { while (start > 0) { System.out.print(start + " "); start--; } System.out.println("Liftoff!"); } What is printed when countDown(3) is called?
53A developer writes the following code: int x = 5; switch (x) { case 1: System.out.print("One "); case 5: System.out.print("Five "); case 10: System.out.print("Ten "); break; default: System.out.print("Other "); } What is printed?
54A developer writes the following code to categorize a temperature reading: ```java int t = 32; if (t < 0) System.out.print("Freezing "); if (t < 32) System.out.print("Cold "); else System.out.println("Mild"); ``` What is printed?
55A developer is writing a switch statement in Java to route a shipment based on a String region code. Which two statements about this switch statement are true? (Choose two.)
56A developer needs to search a two-dimensional array of sensor readings for a target value and stop scanning as soon as the value is found. The code is: ```java int[][] grid = {{1, 2}, {3, 4}}; int target = 3; boolean found = false; for (int r = 0; r < grid.length; r++) { for (int c = 0; c < grid[r].length; c++) { if (grid[r][c] == target) { found = true; break; } } } ``` What is the effect of the break statement in this code?
Deep-dive questions
The most-searched questions in this domain — detailed explanations, worked examples, full answer breakdowns.
Candidates must trace Java control flow precisely and select the right branching statement for a scenario. The most important thing is to know exactly when break, continue, and return transfer control, and to predict loop iteration counts without relying on fall-through assumptions.
The Courseiva 1Z0-811 question bank contains 56 questions in the Control Flow and Loops domain, covering the 14% of the exam attributed to this domain in the official Oracle blueprint. Click any question to see the full explanation and answer breakdown.
Start with a 10-question focused session to identify your baseline accuracy in this domain. Read every explanation — even for questions you answer correctly — to understand the reasoning. Once you score consistently above 80%, move to a 20–30 question session to confirm depth before moving to the next domain.
Yes — the session launcher on this page draws questions exclusively from the Control Flow and Loops domain. Choose 10, 20, 30, or 50 questions for a focused session, or click individual questions to review them one by one.
Save your results, see per-domain analytics, and get readiness scores — free, for every certification.
Sign Up FreeFree forever · Every certification included