Programming stepper motors to move until limit switches

Is the limit switch momentary, i.e. once past the limit switch it stops triggering?

Either way I think your approach is problematic. Steppers motors are inherently open loop, you need to add some closed loop behaviour. This is easier if you are controlling the motors directly, but in this case it appears you are setting a velocity, and some other part is actually generating the steps.

Your current code might work if you either poll the limit switches constantly, or better use an interrupt. When the switch is triggered, change the velocity direction. There may still be an issue with deceleration overshooting the trigger. Possibly that could be solved by moving the limit switch?

However, the ClearCore library appears to have support for limit switches. Once configured, it will automatically stop motion when the trigger is reached, which appears to be what you want. You would then need to poll the motor interface to see if motion has stopped, or perhaps there is an alert.

There are other possibilities, but using the builtin limit switch support might be ok.