<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html><body>
<p>Hello,</p>
<p>In section 4.4 "break and continue..." of the v2.7.2 tutorial documentation the loop iterates and returns a different output than what is depicted.&nbsp;</p>
<pre>Documentation printed output:</pre>
<pre>&nbsp;</pre>
<pre><span class="go">2 is a prime number</span>
<span class="go">3 is a prime number</span>
<span class="go">4 equals 2 * 2</span>
<span class="go">5 is a prime number</span>
<span class="go">6 equals 2 * 3</span>
<span class="go">7 is a prime number</span>
<span class="go">8 equals 2 * 4</span>
<span class="go">9 equals 3 * 3</span></pre>
<div><span class="go"><br /></span></div>
<p><span class="Apple-style-span" style="white-space: pre-wrap;">Here is the code:</span></p>
<pre>&nbsp;</pre>
<pre><span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">10</span><span class="p">):</span>
<span class="gp">... </span>    <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="n">n</span><span class="p">):</span>
<span class="gp">... </span>        <span class="k">if</span> <span class="n">n</span> <span class="o">%</span> <span class="n">x</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="gp">... </span>            <span class="k">print</span> <span class="n">n</span><span class="p">,</span> <span class="s">'equals'</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="s">'*'</span><span class="p">,</span> <span class="n">n</span><span class="o">/</span><span class="n">x</span>
<span class="gp">... </span>            <span class="k">break</span>
<span class="gp">... </span>    <span class="k">else</span><span class="p">:</span>
<span class="gp">... </span>        <span class="c"># loop fell through without finding a factor&nbsp;</span>
</pre>
<p><span class="Apple-style-span" style="white-space: pre-wrap;"><span class="gp">... </span> <span class="k">print</span> <span class="n">n</span><span class="p">,</span> <span class="s">'is a prime number'</span></span>&nbsp;</p>
<p>&nbsp;</p>
<p>My printed output:&nbsp;</p>
<pre>3 is a prime number<br />4 equals 2 * 2<br />5 is a prime number<br />5 is a prime number<br />5 is a prime number<br />6 equals 2 * 3<br />7 is a prime number<br />7 is a prime number<br />7 is a prime number<br />7 is a prime number<br />7 is a prime number<br />8 equals 2 * 4<br />9 is a prime number<br />9 equals 3 * 3</pre>
<pre>&nbsp;</pre>
<pre>&nbsp;</pre>
<pre><span class="s">I added a break statement to the else clause:</span></pre>
<pre><span class="s"><br /></span></pre>
<pre>&gt;&gt;&gt; for n in  range(2, 10):<br />        for x in range(2, n):<br />                if n% x == 0:<br />                        print n, 'equals', x, '*', n/x<br />                        break<br />                else:<br />                        print n, 'is a prime number'<br />                        break</pre>
<pre>&nbsp;</pre>
<pre>To get what is in the tutorial:</pre>
<pre>&nbsp;</pre>
<pre><span class="go">2 is a prime number</span>
<span class="go">3 is a prime number</span>
<span class="go">4 equals 2 * 2</span>
<span class="go">5 is a prime number</span>
<span class="go">6 equals 2 * 3</span>
<span class="go">7 is a prime number</span>
<span class="go">8 equals 2 * 4</span>
<span class="go">9 equals 3 * 3</span></pre>
<pre><span class="go"><br /></span></pre>
<pre><span class="go"><br /></span></pre>
<pre>I hope this helps.</pre>
<pre><span class="go"><br /></span></pre>
<pre><span class="go">Phil Templeton</span></pre>
<pre><span class="s"><br /></span></pre>
<div>&nbsp;</div>
</body></html>