Ad space (banner)
๐Ÿ”งC Lessons
Lesson 4 / 68

Conditionals (if statements)

This lesson covers writing if statements in C, so you can branch logic based on a condition. It's for anyone searching "C if statement syntax."

if / else if / else branches your logic. It helps to picture it as translating a human decision โ€” "if it's raining, bring an umbrella" โ€” into code.

The example uses if / else if / else to display one of three messages depending on the value of score. Comparisons use operators like >, <, and ==, and stacking more else ifs lets you naturally express three or more branches.

A common early mistake is not knowing that historically, C had no dedicated boolean type โ€” 0 is treated as false, and anything else as true. Not knowing this can lead to misreading what a condition actually means.

In real projects, the if statement is a basic building block used in nearly every program โ€” validating input, branching logic based on state, and more.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run C directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)