Do the while loop examples in the Maestro User's Guide clean the stack?

There is the following example in Maestro Servo Controller’s User’s Guide:

10 # start with a 10 on the stack
  dup     # copy the number on the stack - the copy will be consumed by WHILE
  while   # jump to the end if the count reaches 0
  8000 1 servo
  500 delay
  4000 1 servo
  500 delay
  1 minus # subtract 1 from the number of times remaining

What I do not understand here is whether this leaves a zero value staying in the stack after the completion of the countdown from 10 to 0.

If this is not the case and if the stack is all clean after running this code, in which line is this stack value being consumed?

If it is left on the stack, should we add a “drop” at the end of the repeat to prevent a potential stack overflow (to prevent these 0 stack values accumulating later in the code if many while loops are used this way)?


A value of 0 is left on the stack after running that script. So, like you suggested, adding drop at the end of that while loop would be useful.

One feature you might find useful is the Step Script button (located at the bottom of the Script tab of the Maestro Control Center), which can be used to incrementally step through each command in the script in order to observe how the stack changes.


Thank you!

1 Like