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:
- The call $GOTO can be placed before or after the label definition in the NC program. A label is searched for in the program in the upward and downward directions.
- The label must always be called and defined at the same program level (locally within the program). Program jumps between the main program and the subroutine, as well as jumps between subroutines, are not permitted (see Fig. 10.1).
- Identical labels may be defined in main programs and subroutines.
- It is possible to jump to the same label from several points in the NC program.
- A $IF-statement may be combined with a $GOTO in the same NC line. In this case, no corresponding $ELSE/$ENDIF construct may be programmed.
- It is allowed to program other NC-commands before and after a $GOTO-command in the same NC line. The jump, however, is the last action in the NC line.
- External jumps to any levels of a $IF-$ELSE-$ENDIF-control block and within and between these levels are possible. Then however, this jump-in level is the active level (condition is assumed as true; see Programming example).
- Jumps within $WHILE, $FOR, $DO, $REPEAT are not allowed.
- Complete exit from a control block by a $GOTO from any level is always allowed.
- Labels in comments (#COMMENT BEGIN, #COMMENT END) are not recognized.
- In string labels, no distinction is made between upper and lower case.
- The maximum number of string labels [6]-6.42 and expression labels [6]-6.41 and the string label length [6]-6.43 are firmly given.
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
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 ...
...
Further Information