Map a day of the week to 'weekday' or 'weekend' using a switch with multiple case values.
← Control Flow · Ref: Q1151
Comma-separated values on one case line, no fallthrough by design:
case "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" category: "Weekday" case "Saturday", "Sunday" category: "Weekend"
Multiple case values replace the need for fallthrough entirely. See Q237.
Example
defines module qa.controlflow.switchmultiplecases defines program SwitchMultipleCasesDemo() stdout <- Stdout() days <- ["Monday", "Saturday", "Wednesday", "Sunday"] for day in days category <- "Unknown" switch day case "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" category: "Weekday" case "Saturday", "Sunday" category: "Weekend" default category: "Unknown" stdout.println(`${day}: ${category}`)
Common mistakes
E01010 — EK9 has no fallthrough and no colons after case. List multiple values with commas on one case line.
Incorrect:
case "Monday": case "Tuesday": case "Wednesday":
Correct:
case "Monday", "Tuesday", "Wednesday"
Other ways to ask this
- I need a switch that groups several values into one case — no fallthrough needed
- In Java I'd use switch with fallthrough for grouping. Write the EK9 multi-value case
- Given a day name, categorise it using multiple values in a single case line
- Handle Monday through Friday in one case and Saturday/Sunday in another
Coming from another language?
Java: case "Mon": case "Tue": (fallthrough). C#: case "Mon": case "Tue": (fallthrough). EK9: case "Monday", "Tuesday" — comma-separated, no fallthrough.
Keywords: values, group, case, switch, weekday, weekend, multiple