Guard clauses return early for invalid or missing input, leaving the main path less nested.

Program

Play the program to classify a score, then select a missing value to follow the first guard.

guard_clause.dart
String classify(int? score) {
  if (score == null) return 'missing';
  if (score < 60) return 'retry';
  return 'pass';
}

void main() {
  int? score = ;
  var label = classify(score);
  print(label);
}
String classify(int? score) {
  if (score == null) return 'missing';
  if (score < 60) return 'retry';
  return 'pass';
}

void main() {
  int? score = ;
  var label = classify(score);
  print(label);
}
guard clause A guard handles an edge case and exits early.
nullable input `int? score` allows the missing-value case.
flat main path After guards, the remaining code is the normal case.