Share

IF statement

The IF statement executes a series of commands when a certain condition is met.

The basic control structure is:

IF <expression> {
    Commands A
}
Commands B

If expression is true then Commands A are executed, followed by Commands B.

If expression is false, then only Commands B are executed.

image

For example, if you want to calculate a toolpath, but do not want to waste time re-calculating a toolpath that has already been calculated:

// If the active toolpath has not been calculated, do so now
IF NOT Computed {
    EDIT TOOLPATH $TpName CALCULATE
}

You must enclose Commands A in braces, {}, and the braces must be positioned correctly. For example, the following command is NOT valid:

IF (radius == 3) PRINT "Invalid radius"

To make this command valid, add the braces:

IF (radius == 3) {
    PRINT "Invalid radius"
}
Tip: The first brace must be the last item on the line and on the same line as the IF.

The closing brace must be on a line by itself.

Was this information helpful?