C - If Else Statement
if-else selects between two alternative blocks.
Learning Objectives
- Write
if-elsebranches for binary choices.
Prerequisites
Example
#include <stdio.h>
int main(void) {
int score = 72;
if (score >= 60) {
printf("pass\n");
} else {
printf("fail\n");
}
}
Common Pitfalls
- Chained
if-elsecan be harder to read thanswitchwhen matching constants.
Checks for Understanding
- What prints when
scoreis 59?
Show answers
fail