while a binary search takes only a logarithmic number of comparisons, measured in the number of cases in the switch statement. Normally, the only method of finding out if this optimization has occurred is by actually looking at the resultant assembly or machine code output that has been generated by the compiler. Advantages and disadvantages In some languages and programming environments, the use of a case or switch statement is considered superior to an equivalent series of if else if statements because it is: Easier to debug (e.g. setting breakpoints on code vs. a call table, if the debugger has no conditional breakpoint capability) Easier for a person to read Easier to understand, and consequently easier to maintain Fixed depth: a sequence of "if else if" statements may yield deep nesting, making compilation more difficult (especially in automatically generated code) Easier to verify that all values are handled. Compilers can issue a warning if some enum values are not handled. Additionally, an optimized implementation may execute much faster than the alternative, because it is often implemented by using an indexed branch table. For example, deciding program flow based on a single character's value, if correctly implemented, is vastly more efficient than the alternative, reducing instruction path lengths considerably. When implemented as such, a switch statement essentially becomes a perfect hash. In terms of the control-flow graph, a switch statement consists of two nodes (entrance and exit), plus one edge between them for each option. By contrast, a sequence of "if...else if...else if" statements has an additional node for every case other than the first and last, together with a corresponding edge. The resulting control-flow graph for the sequences of "if"s thus has many more nodes and almost twice as many edges, with these not adding any useful information. However, the simple branches in the if statements are individually conceptually easier than the complex branch of a switch statement. In terms of cyclomatic complexity, both of these options increase it by k−1 if given k cases. Switch expressions Switch expressions are introduced in Java SE 12, 19 March 2019, as a preview feature. Here a whole switch expression can be used to return a value. There is also a new form of case label, where the right-hand-side is a single expression. This also prevents fall though and requires that cases are exhaustive. In Java SE 13 the yield statement is introduced,