Skip to main content

Control Statements in Java

Learn Control Statements in Java (Java Basics, Java) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

1. Introduction A control statement decides which line of code runs next. Decision statements are if, if-else, the else-if ladder, nested if and switch , and they always test a boolean condition (if with an int is a compile error). Switch compares one value against constant labels and, since Java 14, can be an expression with arrow labels that yields a value Java 21 adds pattern matching in switch .

More lessons in Java Basics