Conditional statements
In the GLaDOS language, you can express a conditional statement in the following way:
<if-statement> ::= 'if' (<expression>) { <statement> }The if keyword is followed by an expression, which is then followed by a block of statements. The block of statements is executed if the expression evaluates to True. If the expression evaluates to False, the block of statements is skipped.
You can also express an if statement with an else clause:
<if-statement> ::= 'if' (<expression>) { <statement> } 'else' { <statement> }The else clause is executed if the expression evaluates to False.
Finaly, the if statement can be expressed with an else if clause:
<if-statement> ::= 'if' (<expression>) { <statement> } 'else if' (<expression>) { <statement> }An expression must evaluate to a boolean value (True or False), if not, it will systematically evaluate to False.
Example:
if (1 == 1) {
print("1 is equal to 1");
}Output:
1 is equal to 1