If Statements
If statements can be used to execute parts of the program only if a condition is true
. The specialist term for this is "branching".
The condition of if
statements can consist of more complex expressions, but always have to evaluate to a bool data type.
Usage¶
Here's a simple example for an if
statement:
counter
is less or equal 10. Optional parentheses
As with the for, foreach and while loops, the parentheses around the head of the if
statement are optional.
Let's take a look at a more complex condition:
Spice | |
---|---|
This piece of code is a bit pointless, but you can see, that you can also have more complex conditions in there.