# If ... Else — C Programming

Source: https://www.geekswithgeeks.com/en/c/c-if-else

> Run code only when a condition holds.

## if / else if / else

Chains are checked top to bottom; the first true branch wins.

```c
if (score >= 90) {
    printf("A\n");
} else if (score >= 80) {
    printf("B\n");
} else {
    printf("C or below\n");
}
```

## Ternary

`int max = (a > b) ? a : b;` — a compact if/else that produces a value.

## switch

`switch` matches one value against discrete `case`s. Forgetting `break` causes fall-through to the next case.
