Conditionals¶
Conditionals are used when you want to execute a block of code only if a certain condition is met.
1. if
statement¶
The if
statement is used to execute a block of code only if a
certain condition is met.
1.1. Example¶
Example of an if
statement
Age3AI.xs | |
---|---|
You can keep restarting the scenario to see the different outcomes.
If the AI Debug Output does not print anything, it means that the random number was greater than or equal to 7. Otherwise you should see the following output:
AI Debug Output | |
---|---|
2. if-else
statement¶
The if-else
statement is used to execute a block of code if a
condition is met, and another block of code if the condition is not met.
Syntax of an if-else
statement
2.1. Example¶
Example of an if-else
statement
3. if-else if-else
statement¶
It is possible to chain multiple if-else
statements together to
execute different blocks of code depending on the value of a variable.
Syntax of an if-else if-else
statement