Page 43 of 229 Start Back Next End ZBasic Language Reference 33 ZBasic Microcontrollers 2.5.5 Debug.Print Statement One technique for debugging a program is called “print statement debugging”. The idea is that to determine how your program is executing you insert statements into the program that display the values of important variables or simply display a distinctive message so that you know what the program is doing. Debug.Print is a special statement intended just for this purpose. The syntax is: Debug.Print [<string-list>][;] The <string-list> element represents zero or more string expressions separated from one another by a semicolon. Each of the string expressions is evaluated in turn, from left to right, and the string result of each is output to the console channel. If the optional trailing semicolon is omitted, a carriage return/line feed will also be output so that the next time something is output to the console channel it will appear on a new line. If you don’t want the subsequent output to be on a new line, simply add the semicolon at the end of the list. This is often done when you need to compute several different values to output. You can use a separate Debug.Print statement for each value and keep them all on the same output line by ending all but the last with a semicolon. It is permitted, syntactically, to specify an empty string list but still include the trailing semicolon. However, this construction does nothing. 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 the console channel. 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.