Simple Processing: Expressions

Expression is the general name given to any kind of calculation in PureBasic, whether it be numeric or string. Expressions can be as simple as a fixed value or it could be a complex mathematical formula involving many operators, variables and fixed values.

Anything which represents a value can be used in an expression. For example, commands can be used in expressions (as you have already experienced with the operators and the Str command) if they return a value. It is then that value which is used in the expression.

You can make your expressions as complex as you like (or fully expand them for readability and clarity). PureBasic will automatically simplify the expression to increase the speed at which is calculated when your program runs.

The following example shows a variety of expressions. You can find the source here.

OpenConsole()

; A simple expression
simple.l = 8
expression.f = simple * 3 + 2

; More complex example
detail$ = "This is the value of "
var_name.s = " expression"
output_string.s = detail$ + var_name + ": " + StrF(expression)
PrintN(output_string)

PrintN("Press return to exit")
Input()
CloseConsole()
End

Output of the expression example