The concept of loop, while and do...while

Hello and thank you for reading this!

I have a program which drives a motor 2 ways with and IC and I had no problems with it up until I needed to add 2 switches to control its movement. This is the original program (segment of it):

  void setup()
{
  digitalWrite(motorpin1,LOW);   //direction up
  digitalWrite(motorpin2,HIGH);
  digitalWrite(pmwpin,HIGH);    //start
  
  delay(5000);  //move for 5 seconds
  
  digitalWrite(pmwpin,LOW);   //stop
  
  delay (50000);  //wait 50 seconds 
  
  digitalWrite(motorpin1,HIGH);  //change the motor direction
  digitalWrite(motorpin2,LOW);
  digitalWrite(pmwpin,HIGH);  //start
  
  delay(140);   //goes for 140 ms
  digitalWrite(pmwpin,LOW);    //it stops, end of the code
}

As you can see from my program it used to run in the setup segment but because from now I need to check always the state of the button it was moved there (switch1 and switch2; true means it's pushed

  void loop()
{
  digitalWrite(motorpin1,LOW);   //direction up
  digitalWrite(motorpin2,HIGH);
  digitalWrite(pmwpin,HIGH);    //start
  
  while ( switch1 == true) {
    digitalWrite(pwmpin, HIGH);  //it's turned on until the switch one's state equals to true
}
 
  
  digitalWrite(pmwpin,LOW);   //stop
  
  delay (50000);  //wait 50 seconds 
  
  digitalWrite(motorpin1,HIGH);  //change the motor direction
  digitalWrite(motorpin2,LOW);
  digitalWrite(pmwpin,HIGH);  //start
  
  while (switch2 == true) {
    digitalWrite(pwmpin, HIGH);  //it's turned on until the switch two's state equals to true
}
  digitalWrite(pmwpin,LOW);    //it stops, end of the code
}

as far as I know, according to the flowchart and the documentation it supposed to do what I've commented there ( move up until s1 pushed, changes direction, waits, then moves down until s2 is pushed then ends the program) but it moves pretty random instead.
I feel like I don't 100% got the concept of looping but I really tried to understand it. If someone could help me I'd appreciate it! Thank you!

But what you stated in the first paragraph is what I'd like to achieve: to keep the variable pwmpin = high up until the switch1 switch gets pushed by the motor's kinetic motion

I made a flowchart of my program, and because I need to test the switch1 's state over and over again I think I have a loop in the good place. And I need the 50 seconds delay because it'll stay there for 50 seconds until it moves back to the next state.

pinMode calls are correct in the original program, I just cut out them from here because they are OK as the "original" program without the switches works properly, the switch1 and switch2 are setted to output at the beginning

Can you clarify this a bit more? I feel like I can't constantly test the states of switch1 and switch2 with an if/else statement because I need to "stop" the program up until the switch changes and makes the program flow forward.

I get it, thank you.