Loops with IF/GOTO

Repeat work with a GOTO loop back to a sequence label instead of copying blocks.

There's no WHILE on the OSP — a loop is a label at the top and an IF[…]GOTO at the bottom that jumps back while there's work left. Keep a counter, step it inside the loop, and test it against the limit. This is the moment a program stops being a list of moves and starts being software.

Read firstWhat Is a CNC Macro? — Start HereA beginner's on-ramp to CNC macro programming for machinists who already write G-code: what macros are, why they matter, variables, math, loops, passing arguments with G65, and a complete first macro worked line by line.

Your turn

A roughing cycle takes VC1 passes, and pass n removes n millimetres. Loop with IF[…]GOTO back to a sequence label, accumulating the total depth removed in VC2 and leaving the last pass number in VC3. (Four passes remove 1+2+3+4 = 10 mm.)

The machine gives you

4 passes:VC1 = 4
6 passes:VC1 = 6

Your program is run once for each set of conditions. It has to work for all of them.

Loading...

This is a learning simulation — always prove out a program on the actual control before you cut metal.