Tue 10 July 2018, in category Conditional
An if...else condition allows you to check for a given condition if its true, that statement is executed, otherwise the else statement is executed.
In the examples below, we're checking an integer variable i to see if it's less than or greater or equal to 10.
if (i < 10) {
System.out.println("i is Less than 10!");
}
else {
System.out.println("i is Greater Than or Equal to 10!");
}
if (i < 10) {
Console.WriteLine("i is Less than 10!");
}
else {
Console.WriteLine("i is Greater Than or Equal to 10!");
}
if i < 10:
print("i is Less than 10!")
else:
print("i is Greater Than or Equal to 10!")
if (i < 10) {
console.log("i is Less than 10!")
}
else {
console.log("i is Greater Than or Equal to 10!")
}
if i < 10 {
fmt.Println("i is Less than 10!")
} else {
fmt.Println("i is Greater Than or Equal to 10!")
}