Conditions or control flow in carbon language is similar to any other language. It has if, elseif and else keywords.
Introduction
if and else provide conditional execution of statements. An if statement consists of:
- An
ifintroducer followed by a condition in parentheses. If the condition evaluates totrue, the block following the condition is executed, otherwise it is skipped. - This may be followed by zero or more
else ifclauses, whose conditions are evaluated if all prior conditions evaluate tofalse, with a block that is executed if that evaluation is totrue. - A final optional
elseclause, with a block that is executed if all conditions evaluate tofalse.
Code Example
if (5 > 6) {
Console.Print("5 is greater than 6");
} else if (5 == 6) {
Console.Print("5 is equals to 6");
} else {
Console.Print("5 is less than 6");
}
Carbon Language Series
- Introduction to Carbon Language.
- How to define variables in Carbon.
- Primitive Types – Bool, Int, Float, String
- Tuple in Carbon
- Struct in Carbon
- Pointers in Carbon
- Operators in Carbon Language
- Conditions & Control Flow in Carbon
- Ternary Operator (if expression) in Carbon
- Switch conditional in Carbon using Match
- Loops in Carbon
- Functions in Carbon