20+ practice questions focused on Control Flow and Loops — one of the most tested topics on the Oracle Java Foundations 1Z0-811 exam. Each question includes a detailed explanation so you learn why the right answer is correct.
Start Control Flow and Loops PracticeA developer writes a loop to iterate over an array of integers. The loop must sum all elements and stop early if the sum exceeds 100. Which control flow construct should be used?
Explanation: Both Option B and Option D are correct. Option B uses a standard for loop with an index, allowing direct array access and an early break when sum exceeds 100. Option D uses an enhanced for-each loop, which also correctly iterates over all elements and exits via break when the condition is met. Option A is incorrect because the while(true) loop has no termination condition and lacks array bounds checking. Option C is incorrect because the do-while loop checks the condition after the body, causing one extra iteration if the sum exceeds 100 during the loop.
Which statement about the for-each loop in Java is true?
Explanation: The for-each loop (enhanced for loop) in Java can be used with arrays and collections. However, if you attempt to remove elements from a collection while iterating using a for-each loop without using an Iterator's remove() method or other concurrent modification handling, a ConcurrentModificationException will be thrown. Therefore, additional logic is required to safely remove elements during iteration. Option D is false because the for-each loop can indeed be used with arrays; it iterates over each element in the array. Options B and C are also false as the for-each loop cannot modify array elements (assigning to the loop variable does not affect the array) and it always iterates in forward order only.
A developer implements a menu-driven application using a switch statement inside a do-while loop. The menu options are 1-4, and option 4 is supposed to exit the application. However, after selecting option 4, the menu is displayed again before the application exits. The code is structured as follows: do { displayMenu(); choice = scanner.nextInt(); switch(choice) { case 1: // process option 1 break; case 2: // process option 2 break; case 3: // process option 3 break; case 4: break; // intended to exit loop } } while(choice != 4); The developer realizes that the break inside the switch only exits the switch, not the loop. What is the correct fix?
Explanation: Use a labeled break to exit the loop. The issue is that the break statement inside the switch only exits the switch block, not the do-while loop. A labeled break allows the program to break out of the outer loop directly. For example: outerLoop: do { displayMenu(); choice = scanner.nextInt(); switch(choice) { case 1: ... case 4: break outerLoop; } } while(choice != 4); Option B is incorrect because continue would skip the rest of the current iteration and re-evaluate the loop condition, but it does not exit the loop. Option C is incorrect because replacing with an if-else chain does not inherently provide a way to exit the loop; you would still need to set a flag or use a labeled break. Option D is incorrect because although setting a flag could work, it is not necessary; a labeled break is a more direct and clean solution in Java.
Which loop is guaranteed to execute its body at least once?
Explanation: The do-while loop is a post-test loop, meaning the condition is evaluated after the loop body executes. This guarantees that the body runs at least once, regardless of whether the condition is initially true or false. In Java, the do-while loop syntax is `do { ... } while (condition);`.
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?
Explanation: A do-while loop guarantees at least one iteration, which is ideal for menu-driven programs where the menu must be displayed before any input is processed. The switch statement provides a clean, readable way to handle multiple discrete choices (like menu options) compared to a chain of if-else statements, and it aligns with Java's control flow best practices for such scenarios.
+15 more Control Flow and Loops questions available
Practice all Control Flow and Loops questions1. Baseline your knowledge
Start with 10 questions to gauge your current understanding of Control Flow and Loops. This tells you whether you need a concept refresher or just practice.
2. Review every explanation
For each question — right or wrong — read the full explanation. Understanding why an answer is correct is more valuable than knowing the answer itself.
3. Focus on exam traps
Control Flow and Loops questions on the 1Z0-811 frequently use trap wording. Look for subtle differences in answers that test your precision, not just general knowledge.
4. Reach 80% consistently
Do repeated sessions until you score 80%+ three times in a row. Then move to mixed-mode practice to test cross-topic recall under realistic conditions.
The exact number varies per candidate. Control Flow and Loops is tested as part of the Oracle Java Foundations 1Z0-811 blueprint. Practicing with targeted Control Flow and Loops questions ensures you can handle any format or difficulty that appears.
Yes. Courseiva provides free 1Z0-811 practice questions across all exam topics and domains. The platform includes topic-based practice, mock exams, missed-question review, bookmarked questions, and readiness tracking — no account required.
Difficulty is subjective, but Control Flow and Loops is a high-priority exam concept tested in multiple ways — direct recall, scenario analysis, and command-output interpretation. Consistent practice is the best way to build confidence.
Launch a full Control Flow and Loops practice session with instant scoring and detailed explanations.
Start Control Flow and Loops Practice →