Conditions or Control Flow in Carbon Language – If, elseif, else

Total
0
Shares
conditions in carbon language - if elseif else

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 if introducer followed by a condition in parentheses. If the condition evaluates to true, the block following the condition is executed, otherwise it is skipped.
  • This may be followed by zero or more else if clauses, whose conditions are evaluated if all prior conditions evaluate to false, with a block that is executed if that evaluation is to true.
  • A final optional else clause, with a block that is executed if all conditions evaluate to false.

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");
}