41 of 172
ZBasic Language Reference 34 ZX Microcontroller Family 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 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. The Select-Case statement executes by first evaluating the <test-expr>. Then the resulting value is compared with the value of each of the expressions in the <case-expr-list> of the first standard case clause, if present. The evaluation of the case expressions and the comparison with the test value is done in order, left to right. As soon a case expression is found whose value is equal to the test value, the statements associated with that case clause are executed and then control transfers to the first statement following the End Select. If none of the expressions in the first case clause match the <test-expr> value, the process is repeated with the second standard case clause and so on until all of the standard case clauses have been tested. When all of the standard case clauses have been tested without finding a matching expression value, if a default case clause exists the statements associated with it are executed.