DynLex Sections

Match / Switch

Use match or switch when you want to compare one value against several choices.

Pattern
[match|switch] [based|] [on|] value:

This is the exact pattern from std.dl. The clearest everyday spelling is usually match based on value:.

Example
import lib/std.dl

set day to 2

match based on day:
    case 1:
        print "Monday" as line
    case 2:
        print "Tuesday" as line
    case 3:
        print "Wednesday" as line

Each case checks the same value. The branch that matches runs.

Try yourself

Change day to 3. Then add a new case 4: branch.