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

Sign Up for Our Newsletters

Get only the best articles delivered to your mail

You May Also Like
operators in carbon language

Operators in Carbon Language

Table of Contents Hide ArithmeticBitwise & BitshiftComparisonConversionLogicalIndexingFunction CallPointerMoveConclusion We have a number of operators in Carbon language like – Arithmetic, Bitwise, BitShift, Comparison, Conversion, Logical, Indexing, function call, pointer, move…
View Post
pointers in carbon language

Pointers in Carbon Language

Pointers in Carbon language are similar to C++. The type of pointers-to-values-of-type-P is written as P*. Carbon pointers do not support pointer arithmetic. What operations are supported by Pointers in…
View Post
introduction to carbon language - what and why it is created

Introduction to Carbon Language

Table of Contents Hide IntroductionFeatures of Carbon LanguageWhy developed Carbon? Why not upgraded C++?Where Carbon could be used?Carbon is written in which language?Code Example Carbon Language is the successor to…
View Post