### 12.2 The `switch` Statement

The `switch` statement was introduced in Octave 2.0.5. It should be considered experimental, and details of the implementation may change slightly in future versions of Octave. If you have comments or would like to share your experiences in trying to use this new command in real programs, please send them to maintainers@octave.org. (But if you think you've found a bug, please report it to bug@octave.org.

The general form of the `switch` statement is

         switch expression
           case label
             command_list
           case label
             command_list
           ...

           otherwise
             command_list
         endswitch

- The identifiers `switch`, `case`, `otherwise`, and `endswitch` are now keywords.
- The label may be any expression.
- Duplicate label values are not detected. The command_list corresponding to the first match will be executed.
- You must have at least one `case` label command_list clause.
- The `otherwise` command_list clause is optional.
- As with all other specific `end` keywords, `endswitch` may be replaced by `end`, but you can get better diagnostics if you use the specific forms.
- Cases are exclusive, so they don't `fall through' as do the cases in the switch statement of the C language.
- The command_list elements are not optional. Making the list optional would have meant requiring a separator between the label and the command list. Otherwise, things like

                switch (foo)
                  case (1) -2
                  ...

  would produce surprising results, as would

                switch (foo)
                  case (1)
                  case (2)
                    doit ();
                  ...

  particularly for C programmers.

- The implementation is simple-minded and currently offers no real performance improvement over an equivalent `if` block, even if all the labels are integer constants. Perhaps a future variation on this could detect all constant integer labels and improve performance by using a jump table.

— Built-in Variable: warn_variable_switch_label

> If the value of this variable is nonzero, Octave will print a warning if a switch label is not a constant or constant expression