Java

Control Statements

13 lessons in this section of the Java tutorial. Work through them in order, or jump to the one you need.

  1. 1.Control Statements

    Control statements determine the flow of execution in a Java program.

  2. 2.if Statement

    The if statement is the most fundamental control flow construct in Java.

  3. 3.if-else Statement

    The if-else statement extends the basic if by providing an alternative block that executes when the condition is false.

  4. 4.Nested if

    A nested if is an if statement placed inside the body of another if or else block.

  5. 5.switch Statement

    The switch statement selects one of several code blocks to execute based on the value of a single expression.

  6. 6.switch Expression

    The switch expression (Java 14+) is a modern alternative to the switch statement that produces a value.

  7. 7.for Loop

    The for loop is the most widely used iteration construct in Java.

  8. 8.while Loop

    The while loop is a condition-controlled loop — it continues executing as long as its boolean condition remains true, without specifying in advance how many iterations…

  9. 9.do-while Loop

    The do-while loop is Java's only post-test loop — the condition is evaluated after the body executes, which guarantees the body runs at least once regardless of the…

  10. 10.Enhanced for Loop

    The enhanced for loop — also called the for-each loop — was introduced in Java 5 to provide a clean, readable syntax for iterating over arrays and any class that…

  11. 11.break Statement

    The break statement immediately terminates the nearest enclosing loop or switch block and transfers control to the first statement after that block.

  12. 12.continue Statement

    The continue statement skips the remainder of the current loop iteration and immediately jumps to the loop's update step (in a for loop) or condition check (in a while…

  13. 13.return Statement

    The return statement exits the currently executing method and optionally passes a value back to the caller.