Chapter 7
138
UM10349_PCNC1100_Manual_0916A
Programming
The subroune keyword denes the acon associated with the subroune label. Valid subroune
keywords and their meanings are detailed in the following table.
Subroutine Keyword Meaning
Sub Begin subroutine denition
Endsub End of subroutine denition
Call Call the subroutine
Do/while/endwhile Execute the subroutine while a condition is true
Repeat/endrepeat Execute the subroutine while a condition is true
If/elseif/else/endif Conditionally execute the subroutine
Break Break out of a while or if/elseif statement
Continue Skip remaining code and restart at top of while or repeat loop
Return Return a value
7.10.1.1 Defining a Subroutine
The sub and endsub keywords are used to dene the beginning and end a subroune. All lines of
code between the sub and endsub keywords are considered to be part of the subroune.
Sub, Endsub, Call Example:
o100 sub
G53 G00 X0 Y0 Z0 (rapid move to machine home)
o100 endsub
...
o100 call (call the subroutine here)
M02
Subrounes can either be dened in the program le or in a separate le. If the subroune is dened
in the same le as the main program that calls the subroune, it must be dened before the call
statement. For instance, this is valid:
o100 sub
G53 G00 X0 Y0 Z0 (rapid move to machine home)
o100 endsub
...
o100 call (call the subroutine here)
M02
But this is not:
o100 call (call the subroutine here)
M02
o100 sub
G53 G00 X0 Y0 Z0 (rapid move to machine home)
o100 endsub
...