title: Button press To Jump to the beginning of a Sketch
body: <p>I have a program that has many different long running sections (can be 15 mins at a time) and it uses an “IF” statement to decide what section to execute.</p>
  
  <p>My problem is that I want to be able to press a button and have it move to another section immediately without having to wait for the current section to complete.</p>
  
  <p>I thought I could use and external interrupt but I see the interrupt just causes the program to stop execute the interrupt code and continue running from the same place it was before the interrupt was called . </p>
  
  <p>I then thought I could use the “goto” statement, but that does not work ether because the compiler complains if your label is outside of the function you are using the “goto” statement.</p>
  
  <p>I have posted my code below I basically want to be able to press the button and have the code move on to the next “IF” statement no matter what it was doing when I pressed the button.</p>
  
  <p>The delays are just their to simulate what the program would do.
  The program is actually for a robot that has many different modes.
  In mode 1 in just navigates around.
  In mode 2 it can be controlled by a controller. 
  In mode 3 it will just sit until the PIR sensor see some thing then it will start roaming around.</p>
  
  <p>So you see the robot could be in any state for any amount of time doing any thing.I want to push a button and have it stop and change modes.</p>
  
  <p><strong>Example code</strong></p>
  
  <pre><code>volatile int state = LOW;
  int mode = 0;
  
  void setup()
  { 
    Serial.begin(9600);  
    attachInterrupt(0, blink, RISING);
  }
  
  void loop()
  {  
    Serial.println();
    Serial.print("##########################");
    Serial.println();
    Serial.print("Start it again");
    Serial.println();
    Serial.print("##########################");
  
   if(mode==0)
    {Serial.println();
    Serial.print("0");
    Serial.println();
    delay(30000);}
  
  if(mode==1)
    {Serial.println();
    Serial.print("1");
    Serial.println();
    delay(30000);}
  
  if(mode==2)
    {Serial.println();
    Serial.print("2");
    Serial.println();
    delay(30000);}
  
   if(mode==3)
    {Serial.println();
    Serial.print("3");
    Serial.println();
    delay(30000);}
  
   if(mode==4)
    {Serial.println();
    Serial.print("4");
    Serial.println();
    delay(30000);}
  
  }
  
  void blink()
  { delay(800); // This is just a delay to allow for the button press 
    if(mode &gt;= 4)
      {mode = 0;}
    else{mode = ++mode ;}
  }
  </code></pre>