Courseiva
Knowledge + Practice
CertificationsVendorsCareer RoadmapsLabs & ToolsStudy GuidesGlossaryPractice Questions
C
Courseiva

Free IT certification practice questions with explained answers for CCNA, CompTIA, AWS, Azure, Google Cloud, and more.

Certification Practice Questions

CCNA practice questionsSecurity+ SY0-701 practice questionsAWS SAA-C03 practice questionsAZ-104 practice questionsAZ-900 practice questionsCLF-C02 practice questionsA+ Core 1 practice questionsGoogle Cloud ACE practice questionsCySA+ CS0-003 practice questionsNetwork+ N10-009 practice questions
View all certifications →

Product

CertificationsCertification PathsExam TopicsPractice TestsExam Dumps vs Practice TestsStudy HubComparisons

Company

AboutContactEditorial PolicyQuestion Writing PolicyTrust Center

Legal

Privacy PolicyTerms of Service

Courseiva is a free IT certification practice platform offering original exam-style practice questions, detailed explanations, topic-based practice, mock exams, readiness tracking, and study analytics for Cisco, CompTIA, Microsoft, AWS, and other technology certifications.

© 2026 Courseiva. Courseiva is operated by JTNetSolutions Ltd. All rights reserved.

Courseiva is an independent certification practice platform and is not affiliated with, endorsed by, or sponsored by Cisco, Microsoft, AWS, CompTIA, Google, ISC2, ISACA, or any other certification vendor. Vendor names and certification marks are used only to identify the exams learners are preparing for.

← Control Flow and Loops practice sets

1Z0-811 Control Flow and Loops • Complete Question Bank

1Z0-811 Control Flow and Loops — All Questions With Answers

Complete 1Z0-811 Control Flow and Loops question bank — all 0 questions with answers and detailed explanations.

52
Questions
Free
No signup
Certifications/1Z0-811/Practice Test/Control Flow and Loops/All Questions
Question 1mediummultiple choice
Read the full Control Flow and Loops explanation →

A 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?

Question 2easymultiple choice
Read the full Control Flow and Loops explanation →

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

Question 3hardmultiple choice
Read the full Control Flow and Loops explanation →

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?

Question 4mediummultiple choice
Read the full Control Flow and Loops explanation →

What is the output of the following code?

int i = 0;
while (i < 5) {
    if (i == 3) {

i++; continue;

}

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

}
Question 5easymultiple choice
Read the full Control Flow and Loops explanation →

Which statement about the for-each loop in Java is true?

Question 6hardmultiple choice
Read the full Control Flow and Loops explanation →

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

Question 7mediummultiple choice
Read the full Control Flow and Loops explanation →

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

Question 8mediummulti select
Read the full Control Flow and Loops explanation →

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

Question 9hardmulti select
Read the full Control Flow and Loops explanation →

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

Question 10mediummultiple choice
Read the full Control Flow and Loops explanation →

What is the output of the code?

Exhibit

Refer to the exhibit.

for (int i = 0; i < 5; i++) {
    if (i == 2) {
        continue;
    }
    System.out.print(i + " ");
}
Question 11hardmultiple choice
Read the full Control Flow and Loops explanation →

What is the value of sum printed?

Exhibit

Refer to the exhibit.

int sum = 0;
for (int i = 1; i <= 10; i++) {
    if (i % 3 == 0) {
        break;
    }
    sum += i;
}
System.out.println(sum);
Question 12hardmultiple choice
Read the full Control Flow and Loops explanation →

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?

Question 13mediumdrag order
Read the full Control Flow and Loops explanation →

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

Drag steps to the numbered slots on the right, or tap a step then tap a slot.

Steps
Order
1Step 1
2Step 2
3Step 3
4Step 4
5Step 5
Question 14mediummatching
Read the full Control Flow and Loops explanation →

Match each Java operator to its description.

Drag a concept onto its matching description — or click a concept then click the description.

Concepts
Matches

Increment by 1

Modulo (remainder) operator

Logical AND (short-circuit)

Checks if an object is of a certain type

Ternary conditional operator

Question 15easymultiple choice
Read the full Control Flow and Loops explanation →

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?

Question 16mediummultiple choice
Read the full Control Flow and Loops explanation →

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?

Question 17hardmultiple choice
Read the full Control Flow and Loops explanation →

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?

Question 18easymulti select
Read the full Control Flow and Loops explanation →

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

Question 19mediummulti select
Read the full Control Flow and Loops explanation →

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

Question 20hardmulti select
Read the full Control Flow and Loops explanation →

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

Question 21easymultiple choice
Read the full Control Flow and Loops explanation →

What is the output of the program?

Exhibit

Refer to the exhibit.

public class LoopTest {
    public static void main(String[] args) {
        int count = 0;
        for (int i = 0; i < 5; i++) {
            if (i == 2) {
                continue;
            }
            count++;
        }
        System.out.println(count);
    }
}
Question 22mediummultiple choice
Read the full Control Flow and Loops explanation →

What is the output of the program?

Exhibit

Refer to the exhibit.

public class SwitchTest {
    public static void main(String[] args) {
        int x = 2;
        switch(x) {
            case 1:
                System.out.print("One ");
            case 2:
                System.out.print("Two ");
            case 3:
                System.out.print("Three ");
                break;
            default:
                System.out.print("Default");
        }
    }
}
Question 23hardmultiple choice
Read the full Control Flow and Loops explanation →

What is printed by the program?

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);
            }
        }
    }
}
Question 24easymultiple choice
Read the full Control Flow and Loops explanation →

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?

Question 25mediummultiple choice
Read the full Control Flow and Loops explanation →

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?

Question 26hardmultiple choice
Read the full Control Flow and Loops explanation →

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?

Question 27easymultiple choice
Read the full Control Flow and Loops explanation →

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?

Question 28mediummultiple choice
Read the full Control Flow and Loops explanation →

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?

Question 29hardmultiple choice
Read the full Control Flow and Loops explanation →

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?

Question 30easymultiple choice
Read the full Control Flow and Loops explanation →

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

Question 31mediummultiple choice
Read the full Control Flow and Loops explanation →

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

Question 32hardmultiple choice
Read the full Control Flow and Loops explanation →

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

Question 33easymulti select
Read the full Control Flow and Loops explanation →

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

Question 34mediummulti select
Read the full Control Flow and Loops explanation →

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

Question 35hardmulti select
Read the full Control Flow and Loops explanation →

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

Question 36easymultiple choice
Read the full Control Flow and Loops explanation →

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?

Question 37mediummultiple choice
Read the full Control Flow and Loops explanation →

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?

Question 38hardmultiple choice
Read the full Control Flow and Loops explanation →

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?

Question 39easymultiple choice
Read the full Control Flow and Loops explanation →

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?

Question 40mediummultiple choice
Read the full NAT/PAT explanation →

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

Question 41hardmultiple choice
Read the full Control Flow and Loops explanation →

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?

Question 42easymulti select
Read the full Control Flow and Loops explanation →

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

Question 43easymulti select
Read the full NAT/PAT explanation →

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

Question 44hardmulti select
Read the full Control Flow and Loops explanation →

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

Question 45mediummultiple choice
Read the full Control Flow and Loops explanation →

Refer to the exhibit. What is the result?

Exhibit

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);
Question 46mediummultiple choice
Read the full Control Flow and Loops explanation →

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?

Question 47hardmultiple choice
Read the full NAT/PAT explanation →

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?

Question 48mediummultiple choice
Read the full Control Flow and Loops explanation →

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?

Question 49hardmultiple choice
Read the full Control Flow and Loops explanation →

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?

Question 50easymulti select
Read the full Control Flow and Loops explanation →

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

Question 51mediummultiple choice
Read the full Control Flow and Loops explanation →

Refer to the exhibit. What is the output?

Exhibit

int count = 0;
for (int i = 0; i < 3; i++) {
    count++;
    if (i == 1) continue;
    count++;
}
System.out.println(count);
Question 52hardmultiple choice
Read the full Control Flow and Loops explanation →

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?

Practice tests

Scored 10-question sessions with instant feedback and explanations.

1Z0-811 Practice Test 1 — 10 Questions→1Z0-811 Practice Test 2 — 10 Questions→1Z0-811 Practice Test 3 — 10 Questions→1Z0-811 Practice Test 4 — 10 Questions→1Z0-811 Practice Test 5 — 10 Questions→1Z0-811 Practice Exam 1 — 20 Questions→1Z0-811 Practice Exam 2 — 20 Questions→1Z0-811 Practice Exam 3 — 20 Questions→1Z0-811 Practice Exam 4 — 20 Questions→Free 1Z0-811 Practice Test 1 — 30 Questions→Free 1Z0-811 Practice Test 2 — 30 Questions→Free 1Z0-811 Practice Test 3 — 30 Questions→1Z0-811 Practice Questions 1 — 50 Questions→1Z0-811 Practice Questions 2 — 50 Questions→1Z0-811 Exam Simulation 1 — 100 Questions→

Practice by domain

Each domain maps to a weighted exam section. Focus on the domain where you are weakest.

What is JavaJava Basics and SyntaxPrimitives, Strings and OperatorsControl Flow and LoopsArrays and MethodsObject-Oriented ProgrammingException Handling and Development Tools

Practice by scenario

Filter questions by type — troubleshooting, exhibit, drag-and-drop, PBQ, ACLs, OSPF, and more.

Browse scenarios→

Continue studying

All Control Flow and Loops setsAll Control Flow and Loops questions1Z0-811 Practice Hub