The $GOTO-statement

In addition to subroutine technique or using control block instructions ($IF, $FOR...), this functionality offers another possibility of branching to different program sections. Setting labels in the NC program and using the GOTO command enables control to be transferred to any point in the program.

There are two possibilities to use the jump statements:

Expression - Label:

N <expr> : Definition
$GOTO N <expr> | $GOTO N<expr>: Jump call

String - Label:

[ <string> ]  Definition
$GOTO [ <string> ]  Jump call

Characteristics:

Programming example

%goto
N05 P1=1
N06 P2=1
N10 G74 X1 Y2 Z3
N11 X0 Y0 Z0
N15 $IF P1==1 $GOTO N40: -> Jump from outside to N40 into a control
block
N20 X10
N25 Y10
N30 $IF P1==2
N35 X20
N40: $IF P2==1
N45 X30
N50: Y30 $GOTO N65: -> Jump to N65 between control block levels
(IF-ELSE)
N55 $ELSE
N60 Y40
N65: X40
N70 $ENDIF
N80 Z99
N999 M30
The $GOTO-statement 1:
Fig. 10.1: Schematic representation of the $GOTO jump command

Programming example

N10 G1 XY 
N20: X100 (Label Definition N20:)
$IF V.L.dummy_1 <100 $GOTO N20(Jump to Label N20 (or N20:))
$IF V.L.dummy_1 >200
$GOTO [LABEL_1](Jump to Label [LABEL_1])
Y20
$ENDIF
[LABEL_1] X0 (Label Definition [LABEL_1])
N30 A0
$FOR V.P.my_var = 0, 4, 1
$IF V.L.dummy_2 <200 $GOTO [CONTINUE](Jump to Label [CONTINUE])
$SWITCH V.P.my_var
$CASE 0
V.P.AXE_X=V.P.GROUP[1].position[V.P.my_var]
$BREAK
$CASE 1
V.P.AXE_Y=V.P.GROUP[1].position[V.P.my_var]
$BREAK
$CASE 2
V.P.AXE_Z=V.P.GROUP[1].position[V.P.my_var]
$BREAK
$CASE 3
V.P.AXE_A=V.P.GROUP[1].position[V.P.my_var]
$DEFAULT
$ENDSWITCH
$ENDFOR
[CONTINUE] (Label Definition [CONTINUE])
N1000 ...
...