Tsallaka zuwa abun ciki
Justice Tech School

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

What does _ match?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.