Skip to content

Switch ​

Evaluates the value paired with the first form the expression matches.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageSwitch✓
Switch(expr, form1, val1, form2, val2, ...)The first valival_i whose formiform_i (evaluated) exprexpr (evaluated) equals; a bare _\_ (Blank) as a formiform_i always matches, as a default case. Stays unevaluated if nothing matches.
Typed signatures
TypePackageApplies
(any, any*) -> anycombinatoricsalways

Domain: Collections

Details
  • Matching is structural equality only, not Wolfram's fuller pattern language — a form is either a literal value or the bare wildcard _\_.

Examples

Basic #

match a literal form

live ↗
InSwitch(2,1,1,2,2,3,3)\mathrm{Switch}(2, 1, 1, 2, 2, 3, 3)Out22
Scope #

fall through to a Blank default

live ↗
InSwitch(99,1,1,_⁡,other)\mathrm{Switch}(99, 1, 1, \operatorname{\_}, \mathrm{other})Outother\mathrm{other}
About
Examples2
Checked againstWolfram Language 1 agree1 unevaluated
CrosswalkWolfram Language

See also: Do