goto
LABEL

The goto statement allows a procedure to arbitrarily jump from one spot to another within the procedure.


Parameters

This statement has one parameter:

label – is the spot the procedure is supposed to jump to. A label is a unique series of letters and numbers that identifies a location within the procedure. The label may not contain any spaces or punctuation except for ., _ and %, and must always end with a colon. The colon is not actually part of the label, it simply identifies the series of letters and numbers as a label instead of a field or variable..


Description

The goto statement jumps directly to another spot in the current procedure. We recommend that you avoid the goto statement if possible. The goto statement tends to make it difficult to understand the logic of a procedure, code with a lot of goto statements is often called “spaghetti” code. However, sometimes judicious use of the goto statement can simplify your code.

The example below jumps back to the beginning of the procedure if there is an error. This procedure has one label, tryOpen, which is on the first line.

tryOpen:
openfile dialog
if error
    goto tryOpen
endif

Here is an alternate procedure that does the same thing, but without the goto statement.

loop
    openfile dialog
    if error
        repeatloop
    endif
endloop

Calculated Goto

The goto statement normally jumps to a fixed location, but you can also use a formula as the goto parameter. In that case, Panorama will calculate the value of the formula (it should be a text value) and then jump to the corresponding label. (If there is no corresponding label, an error will occur. You can trap this error with the if error statement.)

The example below shows how a calculated goto can be used to implement a .CustomMenu procedure. Using the calculated goto the procedure can quickly jump to the right spot for each menu item. You could also do this with a series of ifelseif statements, but the calculate goto will be much faster if there are a lot of options.

goto replace(info("trigger"),"...","")
if error
    message "Unknown menu item: "+info("trigger")
    rtn
endif

Menu.File.Open:
    ...
    ...
    rtn

Menu.File.Close:
    ...
    ...
    rtn

Menu.File.Save:
    ...
    ...
    rtn

Menu.Edit.Cut:
    ...
    ...
    rtn

Menu.Edit.Copy:
    ...
    ...
    rtn

Menu.Edit.Paste:
    ...
    ...
    rtn

If your formula consists entirely of a single field or variable name, Panorama will think that you are trying to do a fixed goto.

goto myChoice ☞ fixed goto

You can force Panorama to use a calculated goto by putting parentheses around the field or variable name:

goto (myChoice) ☞ calculated goto

Note: You can use the info(“labels”) function if you need a list of the available labels in the current procedure.


See Also


History

VersionStatusNotes
10.0UpdatedCarried over from Panorama 6.0 but now includes the *calculated goto* option that allows the goto label to be calculated on the fly.