switch Statement

The switch statement provides an alternative to using multiple if else statements. It evaluates an expression and executes the corresponding case block.

void main() {
  String grade = 'B';

  // Switch statement
  switch (grade) {
    case 'A':
      print('Excellent');
      break;
    case 'B':
      print('Good');
      break;
    case 'C':
      print('Fair');
      break;
    case 'D':
      print('Poor');
      break;
    default:
      print('Invalid grade');
  }
}