cover

Switch in Dart #

In last lesson you learned about the decision making using if else. There is one more way of making decision in programming.

In if we can compare any two variables and make decision. You can also say if else works using bool data.

switch case works base of comparison of two data of same data types. You can’t do less than or greater than comparison or not equal to comparison. You have to do equal to comparison.

main.dart
void main(){
    
    int input = 2;

    switch(input){
        case 1 : print("Input is 1");
                break;
        case 2 : print("Input is 2");
            break;
        case 3 : print("Input is 3");
            break;
        default : print('No case match');
    }
}