Flow control, part 1
In itself, an unbroken sequence of statments can not do much. Sometimes, you need to react to certain conditions being present, and branch out into different parts of your script.
This is where flow control comes in. Flow control encompasses everything that changes the flow of statements. It allows you to execute different sequences of statements when a condition is fulfilled, or repeat statements a defined (or undefined) number of times.
Conditions
Most flow control works with conditions, which is why we first take a look at those. A condition is something that always evaluates to either true or false (in other words, a boolean data item).
A few examples will make this clearer. The follwoing are conditions
if a and b are conditions, then:
To summarize:
In itself, an unbroken sequence of statments can not do much. Sometimes, you need to react to certain conditions being present, and branch out into different parts of your script.
This is where flow control comes in. Flow control encompasses everything that changes the flow of statements. It allows you to execute different sequences of statements when a condition is fulfilled, or repeat statements a defined (or undefined) number of times.
Conditions
Most flow control works with conditions, which is why we first take a look at those. A condition is something that always evaluates to either true or false (in other words, a boolean data item).
A few examples will make this clearer. The follwoing are conditions
- _a > 1 - True if the value of _a is greater than 1
- _a != 2 - True if the value of _a is not equal to 1
- _a == 3 - True if the value of _a is exactly 3. Not the double equals sign. "==" is used to differentiate from the pure assignement, "=".
- alive player - true if the player is alive
- not alive player - true if the player is NOT alive
- _a >= 3 and _a <= 5 - true if the value of _a is between _3 and _5 (so, greater or equal to 3 and less than or equal to 5)
- _a >= 3 && _a <= 5
- !alive player
if a and b are conditions, then:
- a and b is true when both a AND b are true
- a or b is true when either a OR b is true
To summarize:
- Conditions always evaluate to true or false, i.e. a boolean value
- Condition values can be negated with "not"
- Conditions can be tied to more complex conditions by the use of the "and" and "or" operators.