# !goto(4)

[Home] [Commands] [Variables] [Macro-Dev] [Glossary]

## NAME

!goto - Unconditional labeled jump
!tgoto - Conditional labeled jump

## SYNOPSIS

!goto label

...

*label

!tgoto condition label

...

*label

## DESCRIPTION

Flow can be controlled within a MicroEmacs 2009 macro using the !goto directive. It takes as an argument a label. A label consists of a line starting with an asterisk (*) and then an alphanumeric label. Only labels in the currently executing macro can be jumped to, trying to jump to a non-existing label terminates execution of a macro. labels may be located at any position within the macro (forwards or backwards from the !goto).

A conditional jump may be implemented with a !tgoto, this takes an additional argument condition, which may be a literal numeric value, a variable or an evaluated expression (see Variable Functions). If the condition evaluates to TRUE (or non-zero) then the branch is taken and control continues from the label.

!tgoto is an ideal replacement for !while(4) and !repeat(4) where nested loops are required.

## EXAMPLE

For example, create a block of DATA statements for a BASIC program:

            insert-string "1000 DATA "
            set-variable %linenum 1000
    *nxtin
            screen-update           ;make sure we see the changes
            set-variable %data @ml"Next number: "
            !if &equal %data 0
                !goto finish
            !endif
            !if &greater $curcol 60
                2 backward-delete-char
                newline
                set-variable %linenum &add %linenum 10
                insert-string &cat %linenum " DATA "
            !endif
            insert-string &cat %data ", "
            !goto nxtin
    *finish
            2 backward-delete-char
            newline

Not that any of us are writing basic programs these days !!

## NOTES

!goto and !tgoto are expensive operations because a symbolic name lookup is performed in the macro file. For time critical macros then the !jump(4) and !tjump(4) directives should be used as these do not perform a symbolic name search. The jump equivalents are source sensitive since a line displacement rather than a label is used - this makes them a little dangerous to use.

## SEE ALSO

Variable Functions, !if(4), !jump(4), !repeat(4), !return(4), !tjump(4), !while(4).

(c) Copyright JASSPA 2009
Last Modified: 2009/08/29
Generated On: 2009/10/12

</HMTL>