if statement
switch statement
See also
The if and switch statements provide condition testing.
The if statement comes in two forms. The short form is convenient if the choice is only between executing and not executing a single statement, which appears on the same line.
The longer form provides the more traditional if-then-else structure. Indentation is a matter of choice, it’s used in these examples merely to improve readability.
The switch statement works by attempting to pattern match the switch value against a series of alternative cases. The switch and case values can all be arbitrary expressions. If any pattern match succeeds, execution begins with the next statement following and continues, skipping over any interspersed case clauses until either the end of the switch block or a break statement is reached.
The break statement used here causes execution to “break out of” the innermost control structure. If you’re nested several layers deep into control structures and want to break out of a higher level structure you can label the higher level structure and specify that name on the break statement.
Condition testing
Miscellaneous statements
Expression operators
Wildcard characters
Tutorial: Expressions
Tutorial: Wildcarding