Repeating Work with WHILE
Accumulate a running total in a WHILE loop instead of copying blocks.
A WHILE <condition> … ENDWHILE block repeats while the condition holds. Step the counter inside the loop or it never ends — the engine will trip its own runaway guard, but your part won't get cut.
Your turn
Your macro is called with a count in R1. Using a WHILE loop, add every number from 1 up to that count into a running total in R2. (With a count of 5 the total is 1+2+3+4+5 = 15.) Keep the counter in R3.
The machine gives you
count of 5:
R1 = 5count of 8:
R1 = 8Your 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.