c / beginner
Snippet
The if-else Statement
The if-else statement allows the program to choose between two code blocks based on a condition. If the condition in the parentheses is true, the first block runs; otherwise, the second block in the 'else' section runs.
snippet.c
1
int score = 75; if (score >= 50) { printf("Pass"); } else { printf("Fail"); }
Breakdown
1
if (score >= 50)
Checks if the variable score is greater than or equal to 50.
2
else
Defines the alternative block that executes if the condition is false.