Skip to content
QuiznExam

Flow Control in Java

Test your knowledge of flow control in Java, including conditional statements, loops, switch statements, break, continue, and control flow techniques.

15
Questions
12 min
Time limit
Medium
Difficulty

No sign-up needed · Last updated:

Save your score

At least 8 characters.

Forgot password?

Related quizzes

All 15 questions and answers Spoilers: this shows the questions and answers. Try the quiz first! Open
  1. 1. What is the primary purpose of flow control statements in Java?

    • A. To control the order in which program statements are executed
    • B. To define database tables
    • C. To create packages only
    • D. To declare variables
    Show answer

    A. To control the order in which program statements are executed

    Flow control statements determine which statements execute, how many times they execute, and in what order.

  2. 2. Which statement is commonly used to execute a block of code conditionally in Java?

    • A. if
    • B. loop
    • C. repeat
    • D. execute
    Show answer

    A. if

    The if statement executes a block of code when its Boolean condition evaluates to true.

  3. 3. Which statement is used to provide an alternative block when an if condition is false?

    • A. else
    • B. otherwise
    • C. default
    • D. alternative
    Show answer

    A. else

    The else block executes when the associated if condition evaluates to false.

  4. 4. Which statement is useful when multiple conditions need to be checked sequentially?

    • A. if-else if-else
    • B. do-only
    • C. for-each-only
    • D. continue-only
    Show answer

    A. if-else if-else

    An if-else if-else chain allows multiple conditions to be evaluated in sequence.

  5. 5. Which Java statement is commonly used to select one block of code based on the value of an expression?

    • A. switch
    • B. select
    • C. choose
    • D. matchOnly
    Show answer

    A. switch

    The switch statement provides multi-way branching based on the value of an expression.

  6. 6. Which keyword is commonly used to stop execution from falling through to the next case in a traditional switch statement?

    • A. break
    • B. stop
    • C. exit
    • D. skip
    Show answer

    A. break

    In a traditional switch statement, break exits the switch after the matching case has executed.

  7. 7. Which loop is generally used when the number of iterations is known or controlled by an initialization, condition, and update expression?

    • A. for
    • B. if
    • C. switch
    • D. try
    Show answer

    A. for

    A for loop combines initialization, a continuation condition, and an update expression in its syntax.

  8. 8. Which loop checks its condition before executing its body?

    • A. while
    • B. do-while
    • C. do-until
    • D. repeat
    Show answer

    A. while

    A while loop evaluates its condition before each iteration, so its body may execute zero times.

  9. 9. Which loop guarantees that its body executes at least once?

    • A. do-while
    • B. while
    • C. for
    • D. enhanced for
    Show answer

    A. do-while

    A do-while loop executes its body before checking the condition, so it always executes at least once.

  10. 10. What does the break statement do inside a loop?

    • A. Terminates the nearest enclosing loop
    • B. Restarts the loop
    • C. Skips only the current statement
    • D. Pauses the program permanently
    Show answer

    A. Terminates the nearest enclosing loop

    The break statement immediately terminates the nearest enclosing loop or switch statement.

  11. 11. What does the continue statement do inside a loop?

    • A. Skips the remainder of the current iteration and proceeds with the next iteration
    • B. Terminates the loop completely
    • C. Restarts the Java program
    • D. Exits the current method
    Show answer

    A. Skips the remainder of the current iteration and proceeds with the next iteration

    The continue statement skips the remaining statements in the current loop iteration and continues with the next iteration.

  12. 12. Which loop is also known as the enhanced for loop in Java?

    • A. for-each loop
    • B. while-each loop
    • C. repeat loop
    • D. foreach-while loop
    Show answer

    A. for-each loop

    The enhanced for statement, commonly called the for-each loop, is used to iterate over arrays and Iterable objects.

  13. 13. What is the output of the following code? int x = 5; if (x > 3) { System.out.println("Yes"); }

    • A. Yes
    • B. No
    • C. 5
    • D. Nothing
    Show answer

    A. Yes

    Since 5 is greater than 3, the condition is true and the program prints Yes.

  14. 14. Which keyword can be used to exit from the current method and optionally return a value?

    • A. return
    • B. break
    • C. continue
    • D. exit
    Show answer

    A. return

    The return statement terminates execution of the current method and can return a value when the method requires one.

  15. 15. Which statement about Java flow control is correct?

    • A. Java provides conditional statements, loops, and branching statements to control program execution
    • B. Java supports only if statements for flow control
    • C. Loops can never be nested in Java
    • D. The switch statement can only be used with floating-point values
    Show answer

    A. Java provides conditional statements, loops, and branching statements to control program execution

    Java provides several flow control mechanisms, including if statements, switch statements, loops, break, continue, and return.