Loops & Accumulation

Add up a series with a WHILE loop instead of copying blocks.

A WHILE [condition] DO1 … END1 block repeats while the condition holds — identical to Fanuc, right down to the two-letter comparators (LT, LE, GT, GE, EQ, NE). Accumulating in a loop is how counters like the built-in #3901/#3902 M30 counts work under the hood.

Read firstMacro Control FlowReference for CNC macro control flow including conditional branches, conditional execution, and iteration loops.

Your turn

You're stepping across #1 holes in a row at a pitch of #2. Using a WHILE loop, add up the distance from the first hole to each hole — 0, then #2, then 2×#2, … — and leave the running total in #101. Leave the loop index in #100. (5 holes at pitch 10 totals 0+10+20+30+40 = 100.)

The machine gives you

5 holes at pitch 10:#1 = 5#2 = 10
4 holes at pitch 25:#1 = 4#2 = 25

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.