Page 40 of 229 Start Back Next End ZBasic Language Reference 30 ZBasic Microcontrollers 2.4.6 Miscellaneous Operators The remaining operators to be described are the string concatenation operator (&) and the address operator (@). For the string contenation operator, both operands must be type String and the result will be type String. Note that the + operator may also be used for concatenating strings. The sole difference between using & and using + is that the former supports automatic value-to-string conversion while the latter does not. The address operator is used to obtain the address of a variable, array element or procedure; it is an alternate means of referring to the DataAddress and CodeAddress properties. In use, the address operator is placed immediately before the variable or procedure name as illustrated below. Dim myVar as Byte Dim addr as UnsignedInteger addr = @myVar ' same as myVar.DataAddress 2.4.7 No "Short Circuit" Evaluation It is important to note that in ZBasic, as in most Basic dialects, every term in an expression is always evaluated irrespective of the intermediate results. This is a technical detail that is significant only when an expression contains function invocations and the act of invoking one or more of the functions involved has “side effects” like modifying a global variable, modifying a parameter passed by reference, or changing the state of the hardware. Consider the evaluation of the conditional expression in the If statement below when the value of the variable a is, say, 10. If (a > 3) Or (foo() > 10) Then [other statements] End If When the expression on the left side of the Or operator is evaluated the result will be True. Because of this fact we know that the resulting value of the entire conditional expression will also be True – nothing on the right hand side can possibly affect the outcome. Nonetheless, the expression on the right hand side of the O® operation will still be evaluated and thus the function foo() will be invoked. Some other computer languages, notably C/C++ and Java, implement the concept of “short circuit evaluation”. In those languages, the evaluation of an expression stops as soon as the result is known. If that were the case here, the right hand side of the Or expression would not be evaluated and, hence, the function foo() would not be invoked. To reiterate, ZBasic does not implement short circuit evaluation. 2.5 Statements Within a subroutine or function you can define variables and use statements to implement the logic required for the functionality of the routine. This section describes the types of statements available. ZBasic statements may be divided into two general categories: simple and compound. An example of a simple statement is the assignment statement where the entire statement is expressed on one line (ignoring possible line continuations). In contrast, a compound statement comprises two or more lines and may contain other statements within it. In many respects, it is convenient to think of a compound statement as if it were a single statement even though it may have many constituent statements. 2.5.1 Assignment Statement The assignment statement is perhaps the most basic and most often used statement in a program. The syntax of an assignment statement is shown below in two forms, one for assigning a value to a scalar variable and one for assigning a value to an array element. <var-name> = <value> <var-name>( <index-list> ) = <value>