Thuta Learning
IntermediateProgrammingbeginner

If / Else

Relax. We'll talk through this in plain words — no textbook voice.

if, else if, else let you branch code paths based on a condition. You'll run into this constantly with things like login status, form validation, pricing rules, and user role permissions.

dart
void main() {
  int score = 82;

  if (score >= 90) {
    print('Grade A');
  } else if (score >= 80) {
    print('Grade B');
  } else if (score >= 60) {
    print('Grade C');
  } else {
    print('Try again with a better study plan.');
  }
}

Dart checks conditions from top to bottom. As soon as score >= 80 is true, it outputs Grade B and doesn't check any further conditions.

You should see
Grade B

Easy traps

  • Get the condition order wrong and you'll get the wrong result. For example, if you put score >= 60 first, even someone who scored 90 could end up with Grade C.
If / Else | Thuta Learning