Page 37 of 229 Start Back Next End ZBasic Language Reference 27 ZBasic Microcontrollers BasicX Compatibility Note In BasicX compatibility mode, when a function is defined as returning an UnsignedInteger or UnsignedLong type, the very first line of the function must be a Set statement 2.4 Expressions Expressions are an important part of most ZBasic programs. They provide the means by which your programs implement the mathematical, logical and comparison operations necessary for your application. Generally, anywhere a value may be used, an expression may be used as well. An expression consists of one or more values, called operands, and one or more operators that indicate the function to perform on the operands. Example b = b * 5 + 3 In this assignment statement, the value being assigned to the variable b is an expression comprising three operands and two operators. Some operators, like both of those in the expression above, are called “binary operators” because they require two operands. Other operators require only one operand and are called “unary operators”. The available operators and their characteristics are described in subsequent sections. ZBasic is a strongly typed language. This means that operands supplied for binary operators must generally be of the same type. The only exception to this rule is the exponentiation operator which allows a restricted mixing of types as described in Section 2.4.3. The order of evaluation of the components of an expression is governed by operator precedence and associativity as described in the next two sections. However, that order may be overridden by the use of parentheses. 2.4.1 Operator Precedence Consider again the example expression b = b * 5 + 3. Each of the operators requires two operands but it may not be immediately clear what the operands are in each case. It could be that the expression above means to add 5 to 3 and then multiply the result by the value of b. On the other hand, it could mean to multiply the value of b by 5 and then add 3 to the result. The property that dictates the order in which operators are applied in this case is called “operator precedence”. An operator having higher precedence has priority over an operator with lower precedence and is therefore applied first. The table below depicts the precedence of ZBasic operators. Operator Precedence Precedence Level Operators 11 (highest) ^ 10 +(unary) -(unary) 9 * / 8 \ 7 Mod 6 + - 5 & 4 = < > <= >= <> 3 Not 2 And 1 Or 0 (lowest) Xor