Flutter ● ● ●

Kodebits Day 41: Switch Expression

Jun 16 2026
Practice control flow with a short dart challenge.

What does this print?

String tag(int n) {
  return switch (n % 2) {
    0 => 'even',
    _ => 'odd',
  };
}
void main() {
  print(tag(4));
}


Try it in the online Dart Playground →

[spoiler title="Solution"]

Answer:

even

Explanation:

switch expressions return a value directly from matching case.

[/spoiler]


Further Reading