title: How to break the loop in an Arduino?
body: <p>I'm trying to write a simple program in Arduino, blinking of a LED.</p>
  
  <p>Program is as shown below.</p>
  
  <pre><code>#define red1 13
  #define amber1 12
  #define green1 11
  
  void setup() {
      // put your setup code here, to run once:
      Serial.begin(9600);  
      pinMode(red1, OUTPUT);
      pinMode(amber1, OUTPUT);
      pinMode(green1, OUTPUT);
  }
  
  void Delay(int sec) {
      for(int i=0;i&lt;sec;i++){
          if (Serial.available())
          {
              Button();
              break;
          }
          delay(1);
       }
  }
  
  void Light()
  {
      digitalWrite(red1,HIGH);
      Delay(5000);
      digitalWrite(red1,LOW);
      digitalWrite(amber1,HIGH);
      Delay(5000);
      digitalWrite(amber1,LOW);
  }
  
  void Button()
  {
      digitalWrite(red1,LOW);
      digitalWrite(amber1,LOW);      
      digitalWrite(green1,HIGH);
      delay(1000);
      digitalWrite(green1,LOW);
  }
  
  void loop() 
  {
      Light();  
  }
  </code></pre>
  
  <p>When ever I enter a value in serial monitor <code>Button()</code> function is executed, it should end as soon as function completes due to a break, but this function keeps repeating continuously? How can I fix this such that whenever a serial monitor is interrupted, <code>Button()</code> is executed onetime and then continues with <code>Light()</code>.</p>