Start Back Next End
  
ZBasic Language Reference
40
ZBasic Microcontrollers
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 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.
2.5.12 Select-Case Statement
The Select-Case compound statement is a multi-way branch statement that can be used in place of an If-
Then-ElseIf chain is certain situations.  The syntax is shown below.
Select Case <test-expr>
Case <case-expr-list>
[<statements>]
...
Case Else
[<statements>]
End Select
The <test-expr> element, known as the selection expression, gives a value that will be tested against
the value(s) given in zero or more standard case clauses.  Each standard case clause begins with the
word Case and is followed by a list of one or more expressions, each of which must evaluate to the same
type as <test-expr>.  If multiple expressions are given, they must be separated from one another by a
comma.  The remainder of the case clause consists of zero or more ZBasic statements.  The type of the
selection expression may be Boolean, an enumeration, any numeric type or String.  The practical
value of using a Boolean type is somewhat limited, however – it’s simpler to just use an If-Then
statement.
There may be at most one default case clause introduced by the keywords Case Else.  The remainder
of the default case clause consists of zero or more ZBasic statements.  If the default case clause is
present, it must be the final case clause.
Previous page Top Next page