switch Statements and Expressions
Dart 3 switch expressions return values. Patterns can match types and conditions.
Example
var n = 3;
var name = switch (n) {
1 => "one",
2 || 3 => "two or three",
_ => "many",
};
print(name);Exercise
Default arm.
=> "many"Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.