title: C program for a counter
body: <p>I want to create a counter. Every 10 seconds I want to check the state of a switch. For example if the switch is closed then the 10 sec counter increments. If it is open it goes back to sleep, wakes up again in 10 seconds and checks the state of switch. When the count reaches e.g 100 then do something. How would I go about doing this</p>
  
  <p>My attempt is:</p>
  
  <pre><code>for(int i=0;i&lt;100;i++){
  if(SW=1) {
      i++;
  }
  else
      i=0;
  }
  </code></pre>