arduino switch question

hi i have made a robot car which navigates a maze by it self and also can be controlled by the phone.so without having to upload the different codes all the time i thought i will put a press switch as per this link (https://www.arduino.cc/en/Tutorial/Switch)
and try to make it so that when a button is pressed the maze solving code will work and if button not pressed the bluetooth code will work. i have written the following code

int LED = 13;
int BUTTON = 2;

void setup(){
pinMode(LED,OUTPUT);
pinMode(BUTTON,INPUT);
}

void loop(){
if(digitalRead(BUTTON) == HIGH){
digitalWrite(LED,HIGH);

}else{
digitalWrite(LED,LOW);
}
}

to test the switch function.

can someone please tell me how to use it for my car to solve the maze when button is pressed and bluetooth manual when button not pressed, Thank you

but when it goes to HIGH yes it will do my code but it goes to LOW as soon i let off the button.Then its the bluetooth code always

boolean doMaze = false;

void loop(){
    if(digitalRead(BUTTON) == HIGH){
         doMaze = !doMaze;  // flip the state of your flag variable
    }
 
    if(doMaze){
         // do your maze code
    }
    else {
         // do your bluetooth code
    }
}

i changed your code to this way,is it correct?

it says error compiling the whole time
btw thank you for helping

yes thats my bad,so i used the state thing and the code works now.
thank you for that
so when i power the car the blutooth thing works first properly,also when button is pressed it starts the maze thing.
thats what i expected to happen.
im really greatful for helping me to do that.

Josh987:
but when it goes to HIGH yes it will do my code but it goes to LOW as soon i let off the button.Then its the bluetooth code always

Maybe you need a slider switch instead of a pressbutton.

Sometimes the simplest solutions are the best.

i have been provided only with a prss switch thank you anyway