All conditional statements start with the letters If. They are one-liners, as all other statements, but can be inmediately followed by a line starting with Else followed by a second statement to be executed if the condition is not met.
In the following examples, the conditional statements and the else statements are in red, the operands in green, the operators in blue, in black are the statements to be executed if conditions are met or their alternatives:
IfInt %e = 3 Say Foo #... IfInt %e = 3 Say Foo Else Say Moo #... IfInt %e = 3 Say Foo Else IfInt %e = 4 Say Moo Else IfInt %e = 5 Say Soo Else Say Hmmm #... IfString "cold" IsIn $a IfString "beer" IsIn $a Gosub ServesColdBeer Else IfString "hot" IsIn $a IfString "tea" IsIn $a Gosub ServesHotTea Else Gosub ServesNothing |
As from version 3.602, blank lines and comment lines are allowed between the IF and ELSE lines. Before this version, the ELSE line must inmediately follow the IF line, as in the example above. So as from 3.602, the following syntax is valid:
IfInt %e = 3 Say Foo # else, do the next line Else Say Moo |
Please note: within conditional statements, elements must be clearly separated by spaces. This includes the operators!
These can be found in Numeric variables and operations.
These can be found in String variables and operations.
These can be found in Location variables and operations.
%teller = 3 #... IfInt %teller > 0 Gosub Nonnulo #... Inc %teller $label2 = "Nullo" IfInt %teller = 1 $label2 = "Primo" Else IfInt %teller = 2 $label2 = "Secundo" Else IfInt %teller = 3 $label2 = "Tertio" Else IfInt %teller > 3 $label2 = "Quarto" Gosub $label2 #... IfString "hello" isin $heard Say "Hello, how are you" #... GetPosition @bot IfLoc @bot IsInSquare "2.999n 2.999w" "2.000s 2000e" Gosub InMySquare End Sub Nullo # ... some code here EndSub Sub Nonnulo # ... some code here EndSub Sub Primo # ... some code here EndSub Sub Secundo # ... some code here EndSub Sub Tertio # ... some code here EndSub Sub Quarto # ... some code here EndSub Sub InMySquare # ... some code here EndSub |