Xbasic

Command Statements

Description

The Xbasic command statements determine the structure and flow of execution in a script. For example, the if .. then statement is used to perform actions conditionally. The following script will make the computer beep if the supplied logical expression, x < 5, evaluates to .T. (TRUE):

if (x < 5) then
    ui_beep()
end if

To perform actions repeatedly, you can use a for .. next statement. For example, the following script makes the computer beep ten times:

for i = 1 to 10
    ui_beep()
next i

Other statements that determine the structure and flow of a script are the SELECT, GOTO, and while statements and their variations.

Skipping to Labels 

A label marks a line in a script that serves as a point of reference for the GOTO and ON ERROR GOTO command statements. The GOTO label and ON ERROR GOTO label statements will resume the execution of the script just after the label.

A label is defined by adding the label delimiter (:) at the end of the label name. When referencing a label, use the label name without the label delimiter. A label name can consist of the same characters in a legal variable name and cannot begin with a number. The label must be the first thing to occur on the script line.

For example, the GOTO statement in the following script skips over the TRACE.WRITELN() method:

if (x > 100) then
    GOTO bye
end if
trace.writeln("The value is: " + ltrim( str(x) ) )
bye:
end

If the label is defined at the end of a script, it must be followed by at least one other statement (probably the end statement). This is important because the GOTO label statement resumes execution at the line after the label; the end statement gives it a line to go to.

See Also