Navigation bar
  Start Previous page
 28 of 156 
Next page End 23 24 25 26 27 28 29 30 31 32 33  

22
Comparison Operators
Function
Type
Operator
Permitted Operand Types
Equality
Binary
=
any
Inequality
Binary
<>
any 
Greater Than
Binary
>
String or any numeric
Greater Than or Equal To
Binary
>=
String or any numeric
Less Than
Binary
<
String or any numeric
Less Than or Equal To
Binary
<=
String or any numeric
2.4.6 Miscellaneous Operators
The remaining operator to be described is the string concatenation 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.
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 Or 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>
Previous page Top Next page