title: How to exit or break from 'for loop' on Arduino C Program
body: <p>I'm not new to the programming world, but for last 2 weeks I'm working with Arduino C++. I have a strange problem. In general, I have a 7-segment display that will act as an up counter when the condition is 01, down counter when the condition is 10, 00 for reset to zero, and 11 for stop (pause in that number).</p>
  <p>The problem is, when the up or down counter is still counting and I've change the state, the 7-segment is still counting! Besides that, I've printed the status of state when state is changed, but nothing happens. I think maybe there's mistakes in my code, I need some advice from you guys. Here is my code:</p>
  <p>*FYI, I've try to use <strong>break</strong>, <strong>return</strong>, also call <strong>loop()</strong>, but nothing happens</p>
  <p>*saklar1 = switch1<br>
  *saklar2 = switch2</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;SevSeg.h&gt;
  
  SevSeg sevseg;
  const int saklar1 = 2;
  const int saklar2 = 3;
  
  void setup() {
    byte sevenSegments = 1;
    byte commonPins[] = {};
    byte sevenPins[] = {11, 10, 9, 8, 7, 6, 5, 4};
    bool resistor = true;
    sevseg.begin(COMMON_CATHODE, sevenSegments, commonPins, sevenPins, resistor);
    sevseg.setBrightness(90);
      
    pinMode(saklar1, INPUT);
    pinMode(saklar2, INPUT);
    Serial.begin(9600);
  }
  
  void loop() {
    checking(digitalRead(saklar1), digitalRead(saklar2));
  }
  
  void checking(bool saklar1, bool saklar2){
    if (saklar1 == LOW &amp;&amp; saklar2 == LOW) {
      setSevSeg(0);
    } else if (saklar1 == LOW &amp;&amp; saklar2 == HIGH) {
      for (int i=0; i&lt;=9; i++) {
        setSevSeg(i);
        if (saklar1 != LOW || saklar2 != HIGH) {
          Serial.println(&quot;STATE CHANGED&quot;); //THIS LINE IS NOT EXECUTED OR PRINTED
          checking(digitalRead(saklar1), digitalRead(saklar2));
        }
      }
    } else if (saklar1 == HIGH &amp;&amp; saklar2 == LOW) {
      for (int i=9; i&gt;=0; i--) {
        setSevSeg(i);
        if (saklar1 != HIGH || saklar2 != LOW) {
          checking(digitalRead(saklar1), digitalRead(saklar2));
        }
      }
    } else if (saklar1 == HIGH &amp;&amp; saklar2 == HIGH) {
      delay(100); //Stop
    }
  }
  
  void setSevSeg(int num) {
    sevseg.setNumber(num);
    sevseg.refreshDisplay();
    delay(500); //1 detik
  }
  </code></pre>