title: How to make if condition true only when variable changes to certain value
body: <p>Let's consider the following program:</p>
  
  <pre><code>while(1)
  {
    if(foo1 == HIGH)
    {
      printf("foo1 is high");
    }
    if(foo2 == HIGH)
    {
      printf("foo2 is high");
    }
  }
  </code></pre>
  
  <p>As these conditions are in <code>while(1)</code> loop when <code>foo1</code> is HIGH <code>printf</code> will keep on printing until <code>foo1</code> is LOW and the same goes for <code>foo2</code>.</p>
  
  <p>Is there any possible way I can only print when the condition becomes true and not continuously? Also when <code>foo1</code> has gone to LOW and becomes HIGH again the if condition should be true again.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>using flags to check condition will not work here because</p>
  
  <pre><code>bool check = false;
  while(1)
  if(foo1 == HIGH &amp;&amp; check == false)
    {
      printf("foo1 is high");
      check = true;
    }
  </code></pre>
  
  <p>this will just make it run once. But lets say after some time if <code>foo1</code> becomes HIGH again then the if condition will not be executed because check is still true as <code>bool check</code> is defined outside <code>while(1)</code>. If we define it inside <code>while(1)</code>, then if condition will keep on going as check will be set to false each time.</p>