Control Flow
Nested If
Nested if statements refine a decision in stages.
Nested If
nested_if.c
#include <stdio.h>
int main(void) {
int score = ;
const char *label = "unknown";
if (score >= 60) {
if (score >= 90) {
label = "honors";
} else {
label = "pass";
}
} else {
label = "retry";
}
printf("%s:%d\n", label, score);
return 0;
}
#include <stdio.h>
int main(void) {
int score = ;
const char *label = "unknown";
if (score >= 60) {
if (score >= 90) {
label = "honors";
} else {
label = "pass";
}
} else {
label = "retry";
}
printf("%s:%d\n", label, score);
return 0;
}
#include <stdio.h>
int main(void) {
int score = ;
const char *label = "unknown";
if (score >= 60) {
if (score >= 90) {
label = "honors";
} else {
label = "pass";
}
} else {
label = "retry";
}
printf("%s:%d\n", label, score);
return 0;
}
nested branch
An inner `if` only runs after the outer condition has chosen that path.
classification
Multiple checks can turn one numeric value into a label.