Thuta Learning
BasicProgrammingbeginner

If...Else

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

if...else is used to run different code blocks depending on a condition. Checking login access, assigning a grade based on a score, checking whether stock is available — they all follow this same logic pattern.

c
#include <stdio.h>

int main() {
  int score = 72;

  if (score >= 80) {
    printf("Grade A");
  } else if (score >= 60) {
    printf("Grade B");
  } else {
    printf("Try again");
  }
  return 0;
}

The program checks the conditions from top to bottom. score >= 80 is false, so it moves on to check the next condition, and score >= 60 is true, so Grade B gets printed.

You should see
Grade B

Info

Put the stricter condition first. In grade logic, score >= 60 if you check this first, even students scoring above 80 could end up landing in B.

Easy traps

  • Getting the order of your else if chain wrong causes logic bugs. Watch out — the compiler won't throw an error, but the result can still come out wrong.
If...Else | Thuta Learning