Further examples of expressions
 

As mentioned on the previous page, operators in expressions have a precedence which determines the order in which they are evaluated. For example,
a=2+3*6

will have the value 20 because the * operator gets evaluated first. This would also be the case if the expression was
a=6*3+2

If the addition has to be calculated first, then you need to put parenthesis round it

a=(2+3)*6

which will give a result of 30.

Expressions can contain as many variables, numbers or strings, operators and parenthesis are you like (obviously, there must be matching opening and closing parenthesis). For example, you could have an expression like

blah = 8
foo = (((6+3-7) / 2 + 20) - blah) * A_Command(foo,2)
which will have the result of 13 (6+3-7=2, then divided by 2=1, then add 20=21, then subtract the value of blah (which is 8)=13) multiplied by the return value of the command "A_Command", itself taking "foo" and "2" as parameters.


Previous: Operators in Blitz2 Programming contents Next


News | Introduction | Search | List/Forum/IRC Webring | Contact
Installation | Troubleshooting | Programming | Archives | Links
Return to home page
Page last modified: 21st January 2002