switch and case

Let’s learn about the switch statement in Dart.

We'll cover the following

Overview

The switch statement is a conditional statement similar to if-else. It has different case clauses specified by the case keyword which are similar to conditions in an if-else statement. switch takes an expression and the case clause which is equivalent to that expression will be executed.

switch differs from if-else in the fact that if statements can only return true or false, and can only be defined as such. Case clauses, on the other hand, are not restricted to boolean values (integers, strings, or compile-time constants). However, make sure the case clauses have the same type as the expression.

Switch statements in Dart are intended for limited circumstances, such as in interpreters or scanners.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy