Lesson 7 of 18
If and Else
If and Else
HolyC's if/else syntax is identical to C. The condition must be in parentheses, and the body can be a single statement or a block in braces.
Basic If
I64 x = 10;
if (x > 5) {
Print("x is greater than 5\n");
}
If-Else
I64 score = 72;
if (score >= 90) {
Print("A\n");
} else {
Print("Not A\n");
}
If-Else If-Else
I64 score = 85;
if (score >= 90) {
Print("A\n");
} else if (score >= 80) {
Print("B\n");
} else if (score >= 70) {
Print("C\n");
} else {
Print("F\n");
}
Comparison Operators
| Operator | Meaning |
|---|---|
== | Equal |
!= | Not equal |
< | Less than |
> | Greater than |
<= | Less than or equal |
>= | Greater than or equal |
Logical Operators
&&— logical AND||— logical OR!— logical NOT
I64 age = 25;
Bool has_id = TRUE;
if (age >= 18 && has_id) {
Print("Access granted\n");
}
Your Task
Given I64 temp = 35:
- If
temp > 30, printHot - If
temp > 20, printWarm - Otherwise print
Cool
Aiwnios HolyC loading...
Loading...
Click "Run" to execute your code.