Executing subprogram after subprogram does not work

Hello fellow arduino programmers,

I'm currently working on a project, in which I have several programs, that all work independently but
when I try to combine them (execute them in a certain order) It mixes stuff up.
As an example my Step1 starts a motor, then I can stop it again by pressing a button. My Step2 does a calibration of a seperate module.
What my program does at the moment:
Step1 starts, Motor starts, moves to Step2, I cannot stop the motor anymore.

What I've done in my code (the simple steps are Programs that I have declared further down in the code but work properly), The Display(); stuff is just to display me in what Step the program currently is.
I tried to force the programs with the if statements to go step by step (not really successefull).

void loop() {
  
  StartMachine=1; 
  // Linearachse raus
  if(StartMachine == 1){
    TextDisplay = String ("Step1");
    Display();
  Step1();
  MotorRaus =1;
  StartMachine =0;
  Serial.println(MotorRaus);
  }

  if((StartMachine ==0) &&(MotorRaus ==1)){ 
    TextDisplay = String ("Step2");//Kalibrierung
    Display();
  Step2();
  FertigDeklariert =1;
  MotorRaus =0;  
  }

  if((FertigDeklariert ==1)&&(MotorRaus==0)){
    TextDisplay = String ("Step3");//Einstellung
    Display();
  Step3();
  FertigEinstellung =1;
  FertigDeklariert =0;
  }

  if((FertigDeklariert ==0)&&(FertigEinstellung ==1)){
    TextDisplay = String ("Step4");//linearachse rein
    Display();
  Step4();
  FertigEinstellung =0;
  }

  
  Display();
}

I hope anyone can help me with that. Thanks for your time and have an awesome day.
best regards,
Sascha

I hope anyone can help me with that.

Without seeing ALL of your program, and a much better description of what it is doing, that is not going to happen.

sadly printing the whole code is not prossible, because it is too big for this forum.
But our local IT department was able to help me out.

To all that might encounter a similar problem:

I needed to declare/lock/save every subprogram with flags, so I can force the second program to only start when the flags in the if loops are true. (I had flags but only in the main loop, which was not enough).

e.g.

void Step1(){
  if (digitalRead(EndtasterVorne) == 0) {
  digitalWrite(MotorON, HIGH);
  }
  if (digitalRead(EndtasterVorne) == 1) {
  digitalWrite(MotorON, LOW);
  MotorOff=1;                                        //this flag here was missing, so he skipped the last if segment
   } 
}

now I only needed to integrate the flag MotorOff into the Step2 Starting condition.

sadly printing the whole code is not prossible, because it is too big for this forum.

Utter nonsense. You can attach files (code) to your post that are far larger than even the largest Arduinos could possibly compile and link and run.

You failed to properly read all of the sticky at the top of the forum that you were supposed to read BEFORE you posted here.

when the flags in the if loops are true.

There is no such thing as an if loop. There is an if STATEMENT but it does NOT loop.