Page 47 of 229 Start Back Next End ZBasic Language Reference 37 ZBasic Microcontrollers One final note: although loop index variables of type Single are allowed, some experienced programmers advise against doing so. This is due to the fact that not all real numbers can be exactly represented as a Single value. Consequently, using a Single loop index variable may not produce the expected results. It is often better to use an integral loop index variable along with an auxiliary real variable to accomplish the desired objective. 2.5.9 Goto Statement The Goto statement allows you to transfer control to a specific point in the sequence of statements that comprise a subroutine or function. The point to which control is transferred is marked by a label statement. The label statement is simply an identifier followed by a colon appearing on a line by itself (except that it may be followed by a comment). Because it interferes with the normal program flow, the Goto statement can be overused resulting in a program that is difficult to understand and, therefore, difficult to maintain. Some programmers believe that a Goto statement should never be used. Others believe that it is acceptable to use a Goto but only if the alternative code structure is even less palatable. The latter strategy is probably the best to adopt. Example Goto doOtherStuff <other-statements> doOtherStuff: <other-statements> 2.5.10 If-Then-Else Statement The if-then-else compound statement is the basic decision making construct in ZBasic. In its simplest form, the syntax is: If <boolean-expression> Then <statements> End If The <boolean-expression> element is an expression whose value is of type Boolean. It most often involves one of the conditional operators that allow you to compare the values of two expressions but it may also simply be the invocation of a function whose return type is Boolean. The <statements> element represents zero or more ZBasic statements possibly including other If statements. This allows you to create nested decision-making statements of arbitrary complexity. Although the construction described above is useful, it is often the case that you want your program to execute a certain set of statements if a condition is true but you want it to execute a different set of statements if the condition is false. The If statement allows this logic using the syntax shown below. If <boolean-expression> Then <statements> Else <statements> End If Sometimes you’ll want to test several different conditions and execute a different set of statements in each case. The If statement allows this logic using the following syntax: