How is it possible to use a while loop to print even numbers 2 through 100?
<p>I am a beginner and I am stuck on this problem, "Write a python code that uses a while loop to print even numbers from 2 through 100. Hint ConsecutiveEven differ by 2."</p>

<p>Here is what I came up with so far: </p>

<pre><code> while num in range(22,101,2):
              print(num)
</code></pre>

<p>Your code has several problems:</p>

<ul>
<li>Substituting <code>while</code> for a statement with <code>for</code> syntax. <code>while</code> takes a bool, not an iterable.</li>
<li>Using incorrect values for <code>range</code>: you will start at 22.</li>
</ul>

<p>With minimal changes, this should work:</p>

<pre><code>for num in range(2, 101, 2):
    print(num)
</code></pre>

<p>Note that I used <code>101</code> for the upper limit of <code>range</code> because it is <em>exclusive</em>. If I put <code>100</code> it would stop at <code>98</code>.</p>

<p>If you need to use a <code>while</code> loop:</p>

<pre><code>n = 2
while n &lt;= 100:
    print (n)
    n += 2
</code></pre>

python loops while-loop