0 day streak
c / beginner
Snippet

Decision Making with if-else

The if-else statement allows your program to execute different code blocks based on a condition. If the condition is true, the 'if' block runs; otherwise, the 'else' block runs.

snippet.c
c
1
2
3
4
5
6
int score = 75;
if (score >= 50) {
// Pass
} else {
// Fail
}
Breakdown
1
if (score >= 50) {
Checks if the variable score is greater than or equal to 50.
2
} else {
Starts the alternative block if the condition above was false.