The $GOTO statement
In addition to the subroutine technique or the use of control block statements ($IF, $FOR...), this functionality offers another option for branching to other program parts. The GOTO command can be called at any point in the NC program by setting jump labels in the NC program.
Syntax: |
There are two options to use jump statements:
Expression label:
N<block_no> : | Definition jump target, block number with colon |
$GOTO N<block_no> | Jump call |
String label:
[<name>] | Definition jump target, name in square brackets |
$GOTO [<name>] | Jump call |
Characteristics:
- The $GOTO call can be placed in the NC program before or after the label definition. A label search is carried out in the program in the upwards and downwards 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 a subroutine as well as jumps between subroutines are not permitted (see figure below).
- 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 associated $ELSE/$ENDIF statement may be programmed.
- Other NC commands may be programmed before and after a $GOTO command in the same NC line. However, the jump is the last action in the NC line.
- External jumps are possible to any levels of a $IF-$ELSE-$ENDIF control block and within and between these levels. 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 permitted.
- Complete exit from any control block statement by a $GOTO from any level is always permitted.
- Labels in comments (#COMMENT BEGIN, #COMMENT END) are not recognised.
- In string labels, no distinction is made between uppercase and lowercase.
- All labels ignored during decoding are stored. The maximum number of storable expression labels [6]-6.41, string label [6]-6.42 and string label length [6]-6.43 are specified.
- At each jump call, a check is made whether the jump label already is known, i.e. stored. If the check is positive, the jump is executed immediately. If the jump label is unknown, the search is started in the active program level from the current NC line in the program level through to program end (M29/M30). If the jump label is not found, error message P-ERR-20840 is output.
- After reaching the maximum number of storable labels and other new jump labels are decoded, these labels are no longer saved. This is displayed by the warnings P-ERR-20829 or P-ERR-20831. At every new jump label call with an unknown label, the search starts again at the start of the current program level. In this case, the jump process may require more time with very large NC programs.
Programing Example
The $GOTO statement
%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 in 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
N51 $ENDIF
N55 $ELSE
N60 Y40
N65: X40
N70 $ENDIF
N80 Z99
N999 M30
Programing Example
N10 G1 XY
N20: X100 ;Label definition N20:
$IF V.L.dummy_1 <100 $GOTO N20 ;Jump to label 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 ...
...