31 lines
659 B
Plaintext
31 lines
659 B
Plaintext
// When you need to check some value
|
|
// a conditional statements might help you
|
|
|
|
int valueToCheck = 2 + 2;
|
|
if (valueToCheck == 4)
|
|
{
|
|
printline("Yay! 2 + 2 = 4");
|
|
}
|
|
|
|
// Conditional statement uses condition in pairs
|
|
// after `if` keyword and executes command(s) after
|
|
// if condition turns out to be true
|
|
|
|
// Otherwise, to execute block when condition turns
|
|
// out to be false, you can use `else` keyword:
|
|
|
|
int age = 30;
|
|
|
|
if (age <= 20)
|
|
printline("You're too young");
|
|
else
|
|
{
|
|
age = 20;
|
|
printline("You looks too young!");
|
|
}
|
|
|
|
// NOTE: If you need to execute only one statement
|
|
// inside `if` or `else` block, then the curly
|
|
// braces can be omitted.
|
|
|