Flow Control
Command | Description | Zen | Plus |
---|---|---|---|
if | Executes a block of code if the condition is met | ✔️ | ✔️ |
else | Executes a block of code if the previous if condition is not met | ✔️ | ✔️ |
else if | Executes a block of code if the previous if condition is not met but the current condition is met | ✔️ | ✔️ |
while | A loop that runs while a condition is met | ✔️ | ✔️ |
do while | A loop that runs at least once | ✔️ | ✔️45 |
for | A loop that runs a set amount of times | ✔️ | ✔️ |
break | Breaks out early while in a loop | ✔️ | ✔️ |
The if command is one of the single most useful tools for your GPC scripting needs. It allows you to control when certain blocks of code are run and it takes any expression, function, or code which returns or has a value. It can also be used in the init, main, combo, and function sections of your code. The if command works by evaluating the expression within it to its boolean value. An expression is anything that has a value. Such as a function call that returns a value, a variable, or a mathematical sum. literal values and comparisons. In computer programming languages, a Boolean is a data type with only two possible values, TRUE or FALSE. In GPC, FALSE means 0 and TRUE is a value other than 0 be it a negative or positive value. If the expression placed within an if commands brackets is TRUE, then the code nested within it is executed, as shown below