Navigation bar
  Start Previous page
 43 of 206 
Next page End  

ZBasic Language Reference
35
ZX Microcontroller Family
Examples
If (i > 3) Then
    Call PutPin(12, zxOutputLow)
Else
    j = 55
    Call PutPin(12, zxOutputHigh)
End If
If i > 3 Then
    Call PutPin(12, zxOutputLow)
ElseIf (i > 0) Then
    j = 0
Else
    j = 55
    Call PutPin(12, zxOutputHigh)
End If
Note that the conditional expression is not required to be enclosed in parentheses.  Many programmers
are accustomed to other languages where they are required and therefore do so out of habit.  Others
believe that the parentheses improve the readability and use them for that reason.  You’re free to adopt
whichever practice suits you.
One other comment on style is in regard to indentation.  The examples used in this document indent the
statements within compound statements like If-Then-Else in order to improve readability.  The compiler
ignores spaces and tabs except to the extent that they separate identifiers, keywords, etc.  You’re free to
adopt any indentation style that you deem appropriate.
There is no fixed limit on how deeply If-Then statements may be nested.  The actual limit is governed by
how much memory is available to the compiler.  For all practical purposes, there is no limit.
2.5.11 Single-line If-Then Statement
Sometimes, it is convenient to express conditional logic concisely using a single-line If statement.  The
form is similar to the multi-line form except that the Else If clause is not supported and there is no End
If.  The syntax of a single-line If statement is:
If <boolean-expression> Then <statement> [ Else <statement> ]
The <boolean-expression> element is the same as described in the previous section.  The
<statement> element represents one ZBasic statement such as an assignment statement or a Call
statement.  Note, that it is permissible to for <statement> to be multiple statements each separated
from the next by a colon.  Moreover, the line continuation character may be used to distribute the
<statement> over multiple lines.
Examples
If (a > b) Then a = b
If (a > b) Then a = b Else b = 10
If flag Then flag = False : Call MySub(25)
BasicX Compatibility Note
The single-line If statement is not supported in BasicX compatibility mode.
Previous page Top Next page