title: Loop Functions C++
body: <p>I've written a code to use a for loop to display all the even numbers with in the range based on the parameters inputted by the user. However, I'm a little confused as to why the i &lt; b in the for statement still outputs b as the final number in the loop being that it isn't and &lt;= symbol. Also if a is an even number it also populates in the output. I've tried using if <code>(i % 2 == 0) &amp;&amp; (i &gt; a)</code> as well as if <code>(i % 2 == 0) &amp;&amp; (i &gt; a)</code> with no avail.</p>
  <p>Here is the code:</p>
  <pre><code>#include&lt;iostream&gt;
  #include&lt;string&gt;
  using namespace std;
  
  //Loop function to display even numbers within a range
  int print_even(int a, int b) {
  
      int i;
      for (i = a; i &lt; b; i++) {
          if (i % 2 == 0)
              cout &lt;&lt; i &lt;&lt; &quot; &quot;;
      }
      return i;
  }
  
  //main function 
  int main() {
      int a, b;
      cout &lt;&lt; &quot;Write the initial number&quot; &lt;&lt; endl;
      cin &gt;&gt; a;
      cout &lt;&lt; &quot;Write the ending number&quot; &lt;&lt; endl;
      cin &gt;&gt; b;
  
      cout &lt;&lt; &quot;These are all the even integers between the initial and ending numbers&quot; &lt;&lt; endl;
      cout &lt;&lt; print_even(a,b);    
  
      return 0;
  }
  </code></pre>
  <p>Here is the output:</p>
  <pre><code>Write the initial number
  2
  Write the ending number
  60
  These are all the even integers between the initial and ending numbers
  2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60
  </code></pre>
  <p>Any feedback would be greatly appreciated!</p>