Conditional Statements execute its Body single time if Condition is TRUE
● if ... else Statement executes single section for which condition is TRUE
● switch...case Statement is used instead if ... else Statement when all conditions evaluate the same variable
● ? TRUE : FALSE Statement executes first section if Condition is TRUE. Otherwise it executes second section.
if ... else
//TEST VARIABLES.
var number = 10
var text = "Hello"
//IF ELSE STATEMENT.
if (number == 10 ) { print("Number is 10" ) }
else if (text == "Hello") { print("Text equals Hello") }
else if (text == "World") { print("Text equals World") }
else { print("No match found" ) }
switch...case
//TEST VARIABLES.
var number = 10
//SWITCH STATEMENT.
switch (number) {
case 10:
print("number = 10") //Only selected case is executed.
case 20:
print("number = 20")
default:
print("Some other value")
}
? TRUE : FALSE
//TEST VARIABLES.
var left = 20
var right = 10
//CONDITION ? TRUE : FALSE
left > right ? print("TRUE") : print("FALSE")