used in place of simple if statement, for example int a = 1; int b = 2; int minVal = (a < b) ? a : b; switch statement Switch statements in Java can use byte, short, char, and int (note: not long) primitive data types or their corresponding wrapper types. Starting with J2SE 5.0, it is possible to use enum types. Starting with Java SE 7, it is possible to use Strings. Other reference types cannot be used in switch statements. Possible values are listed using case labels. These labels in Java may contain only constants (including enum constants and string constants). Execution will start after the label corresponding to the expression inside the brackets. An optional default label may be present to declare that the code following it will be executed if none of the case labels correspond to the expression. Code for each label ends with the break keyword. It is possible to omit it causing the execution to proceed to the next label, however, a warning will usually be reported during compilation. switch (ch) { case 'A': doSomething(); // Triggered if ch == 'A' break; case 'B': case 'C': doSomethingElse(); // Triggered if ch == 'B' or ch == 'C' break; default: doSomethingDifferent(); // Triggered in any other case break; } switch expressions Since Java 14 it has become possible to use switch expressions, which use the new arrow syntax: var result = switch (ch) { case 'A' -> Result.GREAT; case 'B', 'C' -> Result.FINE; default -> throw new ThisIsNoGoodException(); }; Alternatively, there is a possibility to express the same with the yield statement, although it is recommended to prefer the arrow syntax because it avoids the problem of accidental fall throughs. var result = switch (ch) { case 'A': yield Result.GREAT; case 'B': case 'C': yield Result.FINE; default: throw new ThisIsNoGoodException(); }; Iteration statements Iteration statements are statements that are repeatedly executed when a given condition is evaluated as true. Since J2SE 5.0, Java has four forms of such statements. while loop In the while loop, the test is done before each iteration. while (i < 10) { doSomething(); } do ... while loop In the do ... while loop, the test is done after each iteration. Consequently, the code is always executed at least once. // doSomething() is called at least once do { doSomething(); } while (i < 10); for loop for loops