thank you for your replay.
actually when i click the button, the motor runs (forever). i need it to stop then i click the button again. this does not work. it still moves.
the button.isPressed() is only checked during that instatnt of time between when the for loop ends and loop() is invoked again.
test this by holding the button down
may need to check for the button being pressed inside the loop or not using a for loop and incrementing the idx and stepping the motor once each iteration of loop() and separately handling the wrap around
on the other hand ... why not just step the motor while loopState == LOOP_STARTED?