title: When to use a while loop or if statement?
body: <p>Can you give some examples of situations where a while loop and a if loop would be appropriate?</p>
  
  <p>I am working on this project where an Arduino reads an analog input from a variable resistor. 
  This is how I have it read the raw input:</p>
  
  <pre><code>int intputValue = analogRead(A0);
  </code></pre>
  
  <p>Then I convert the raw input into a number between 0 and 100 for percentage:</p>
  
  <pre><code>double percentValue = inputValue * (1.0/10.23);
  </code></pre>
  
  <p>So then I use this percentValue to determine whether the Arduino needs to send signal(s) through several of its digital pins. I have signals going to a 4 channel relay module. Basically my idea is that if the percentValue is between 0-25, one of the relays would turn on, hence only one digital pin would need to be activated. Between 26-50, two pins, 51-75, three pins, and 76-100, four pins. </p>
  
  <p>Here's my question: Should I use a if statement:</p>
  
  <pre><code>if(percentValue &gt;=0 &amp;&amp; percentValue &lt;=25){
     digitalWrite(pin1, HIGH);      //turns on pin 1
  }
  </code></pre>
  
  <p>Or use a while loop:</p>
  
  <pre><code>while(percentValue &gt;= 0 &amp;&amp; percentValue &lt;=25){
     digitalWrite(pin1, HIGH);       //turns on pin 1
  }
  </code></pre>
  
  <p>Then I'm going to do a similar thing for the rest of the percentValue ranges.
  Is there a difference between using "if" and "while" in this case?</p>
  
  <p>Thanks for any help.</p>