if - else statements
The most commonly used statement block within the Gosu language is the if block. The if block uses a multi-part construction. The else block is optional.
Syntax
if (<expression>) <statement>
[ else <statement> ]Example
if (a == b) { print("a equals b") }
if (a == b || b == c) { print("a equals b or b equals c") }
else { print("a does not equal b and b does not equal c") }
if (a == b) { print("a equals b") }
else if (a == c) { print("a equals c") }
else { print("a does not equal b, nor does it equal c") }
To improve the readability of your Gosu code, Gosu automatically downcasts after a typeis expression if the type is a subtype of the original type. This is particularly useful for if statements and similar Gosu structures. Within the Gosu code bounded by the if statement, you do not need to do casting (as TYPE expressions) to that subtype. Because Gosu confirms that the object has the more specific subtype, Gosu implicitly considers that variable’s type to be the subtype, at least within that block of code.
See also
