In the switch case, the default
statement is utilized when no condition matches.
switch(variable_expression) {
case constant_expr1: {
// statements;
}
break;
default: {
//statements;
}
break;
}
The following code shows how to implement the default
statement in Dart:
// dart programvoid main(){int num = 3;switch (num) {case 1: {print("Shot 1");} break;case 4: {print("Shot 4");} break;default: {print("This is default case");} break;}}
main()
function. In the main()
:
num
of int type and assigned value to it.num
is tested against cases in the switch. If the value of num
matches one of the cases, the corresponding code block is executed. Otherwise, the code within the default block is executed.