In Dart, switch-case statements are a simplified version of the nested if-else statements. Its approach is the same as that in Java.
Syntax:
switch ( expression ) {
case value1: {
// Body of value1
} break;
case value2: {
//Body of value2
} break;
.
.
.
default: {
//Body of default case
} break;
}
The default case is the case whose body is executed if none of the above cases matches the condition.
Rules to follow in switch case:
- There can be any number of cases. But values should not be repeated.
- The case statements can include only constants. It should not be a variable or an expression.
- There should be a flow control i.e break within cases. If it is omitted than it will show error.
- The default case is optional.
- Nested switch is also there thus you can have switch inside switch.

Example 1: Normal switch-case statement
void main() { int gfg = 1; switch (gfg) { case 1: { print("GeeksforGeeks number 1"); } break; case 2: { print("GeeksforGeeks number 2"); } break; case 3: { print("GeeksforGeeks number 3"); } break; default: { print("This is default case"); } break; } } |
chevron_right
filter_none
Output:
GeeksforGeeks number 1
Example 2: Nested switch-case statement
void main() { int gfg1 = 1; String gfg2 = "Geek"; switch (gfg1) { case 1: { switch (gfg2) { case 'Geek': { print("Welcome to GeeksforGeeks"); } } } break; case 2: { print("GeeksforGeeks number 2"); } break; default: { print("This is default case"); } break; } } |
chevron_right
filter_none
Output:
Welcome to GeeksforGeeks
Recommended Posts:
- How to Combine Lists in Dart?
- Basics of Numbers in Dart
- Dart - Super and This keyword
- Dart - Standard Input Output
- Generators in Dart
- Dart - Classes And Objects
- Operators in Dart
- Dart - Loops
- Dart - Loop Control Statements (Break and Continue)
- Dart Programming - Functions
- Instance and class methods in Dart
- Abstract Classes in Dart
- Labels in Dart
- Dart Programming - List
- Different Types of Functions in Dart
- Dart - Splitting of String
- Method Overriding in Dart
- Concept of Isolates in Dart
- Concept of Callable Classes in Dart
- Getter and Setter Methods in Dart
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

