While statement on controller with 2 programs

How do i use a while statement to control 1 motor with 2 programs only when we press a button on the controller not when i let go. Are current program runs the program but never stops.

while(Controller1.ButtonUp.pressing()){
BAMotor.spin(directionType::fwd,15,velocityUnits::pct);
}
while(Controller1.ButtonDown.pressing()){
BAMotor.spin(directionType::rev,15,velocityUnits::pct);
}}}

this is our current program can someone please tell me what we are doing wrong???

Use an if statement to see if it works

You need a statement that turns off the motor. One option is that every interval through your loop set a variable to false, but then set it to true if either button is pressing. At the end, if the statement is still false, turn off the motor

We were using an if statement but the computer ignored one of the statements istead of running both

while (true){
   if (Controller1.ButtonUp.pressing()){
      BAMotor.spin(directionType::fwd,15,velocityUnits::pct);
   }
   else if((Controller1.ButtonDown.pressing()){
      BAMotor.spin(directionType::rev,15,velocityUnits::pct);
   } else {
      BAMotor.spin(directionType::rev,0,velocityUnits::pct);
   }
}

Only one while loop can run at once, and spin just sets the velocity. You need to set the velocity to zero if you want it to stop

The OP’s code functions properly, the loop exits when the button is released - the motor just isn’t ever told to turn off.

EDIT: the OP’s code stops all other operations when a button is pressing. Your code would be better, but in the context of just one motor being controlled, this would be fine.

also just realized that you have it spinning at 15 in both loops