39 of 208
ZBasic Language Reference 31 ZX Microcontroller Family Note that each of the items to be displayed must be a string. You can use the CStr() function to produce a string from any value. Examples Dim i as Integer Dim s as String Debug.Print CStr(i) Debug.Print "i = ";CStr(i) Debug.Print "s = "; Debug.Print s Debug.Print The last example, with an empty <string-list> and no trailing semicolon, will simply send a carriage- return/linefeed to Com1. The unusual form of Debug.Print is due to its heritage from Visual Basic. It should probably be called the Print method of the system Debug object but it even departs from the traditional syntax of the methods that are part of object-oriented languages. Nonetheless, it is included for compatibility as well as its utility. 2.5.6 Do-Loop Statement and Variants This compound statement, briefly mentioned earlier in this document, is the basic repetition construct in ZBasic. The syntax is: Do [<statements>] Loop This construct causes the sequence of zero or more statements to be repeatedly executed. However, execution of the loop may be terminated using an Exit Do statement at which point control will transfer to the first statement following the Loop statement. Note that the Do-Loop compound statement may be nested and the Exit Do only terminates the innermost Do-Loop that contains it. Example Do <other-statements> Do <other-statements> If (i > 5) Then <other-statements> Exit Do End If Loop <other-statements> Loop Here, the Exit Do only terminates the inner Do-Loop; the outer one continues to iterate. There are four other variations on this basic looping concept, all of which involve a condition for continuing the iteration. The syntax of the four variations is as follows: Do While <boolean-expression> [<statements>] Loop