<br><font size=2 face="sans-serif">You should probably read some of the
links sent to you earlier but here is a stab at an explanation.</font>
<br>
<br>
<br><font size=2><tt>Richard Hultgren wrote on 12/08/2009 10:36:08 AM:<br>
<br>
&gt; ----- Forwarded Message ----<br>
&gt; From: Richard Hultgren &lt;hultgren1946@yahoo.com&gt;<br>
&gt; To: tutor@python.org<br>
&gt; Sent: Mon, December 7, 2009 2:53:40 PM<br>
&gt; Subject: loops</tt></font>
<br><font size=2><tt>&gt; I'm quite new but determined. &nbsp;Can you explain
to me, step by step, what is going on in the computer in this loop. &nbsp;I
<br>
&gt; hope I am not being too dumb!<br>
</tt></font>
<br><font size=2><tt>&gt; a = 0<br>
&gt; b = 1<br>
&gt; count = 0<br>
&gt; max_count = 20</tt></font>
<br>
<br><font size=2><tt>The above steps are initialization of your variables.
&nbsp;'a' points to the value 0, 'b' points to 1, etc.</tt></font>
<br><font size=2><tt>Since the values of the variables are used within
the loop we need to give it somewhere to start, otherwise we will get an
error. </tt></font>
<br><font size=2><tt><br>
&gt; while count &lt; max_count:<br>
</tt></font>
<br><font size=2><tt>The while loop will continue until 'count &lt; max_count'
evaluates to False (20 loops, due to line below)</tt></font>
<br><font size=2><tt>the loop is defined as everything that is indented
below this line.</tt></font>
<br>
<br><font size=2><tt>&gt; &nbsp; &nbsp; count = count + 1<br>
</tt></font>
<br><font size=2><tt>Increase the value of count by one each loop iteration,
otherwise the statement 'count &lt; max_count' will never change value,
and the loop will never end.</tt></font>
<br>
<br><font size=2><tt>&gt; &nbsp; &nbsp; # we need to keep track of a since
we change it<br>
&gt; &nbsp; &nbsp; old_a = a &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;# especially here</tt></font>
<br><font size=2><tt>&gt; &nbsp; &nbsp; old_b = b</tt></font>
<br>
<br><font size=2><tt>Keep the old values of the variables since we want
to add them together for the new value of b and will change the values
in the next steps. &nbsp;<br>
</tt></font>
<br><font size=2><tt>&gt; &nbsp; &nbsp; a = old_b<br>
&gt; &nbsp; &nbsp; b = old_a + old_b<br>
</tt></font>
<br><font size=2><tt>reassign 'a' to the value of 'old_b'. &nbsp;If we
didn't save the value of 'a' into 'old_a' above we wouldn't know what it
was anymore.</tt></font>
<br><font size=2><tt>reassign 'b' to the sum of 'old_a' and 'old_b'</tt></font>
<br>
<br><font size=2><tt>&gt; &nbsp; &nbsp; # Notice that the , at the end
of a print statement keeps it<br>
&gt; &nbsp; &nbsp; # from switching to a new line<br>
&gt; &nbsp; &nbsp; print old_a,</tt></font>
<br><font size=2><tt>prints the value of old_a followed by a space. &nbsp;Without
the comma at the end the print statement each loop would print on a new
line.</tt></font>
<br>
<br>
<br><font size=2><tt>The best way to follow what is happening is to trace
the variables through the program. &nbsp;you would get a table that loops
something like :</tt></font>
<br>
<br><font size=2><tt>max_count &nbsp; &nbsp; &nbsp; &nbsp;count
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a
&nbsp; &nbsp; &nbsp; &nbsp;b &nbsp; &nbsp; &nbsp; &nbsp;old_a
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;old_b
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;count&lt;max_count
&nbsp; &nbsp; &nbsp; &nbsp;OUTPUT</tt></font>
<br><font size=2><tt>20 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;0 &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp;
&nbsp; &nbsp;no Value &nbsp; &nbsp; &nbsp; &nbsp;No Value
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;T
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;No
output yet &nbsp; &nbsp; &nbsp; &nbsp; </tt></font>
<br><font size=2><tt>20 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp;1 &nbsp; &nbsp;
&nbsp; &nbsp;0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;T &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp;
&nbsp; &nbsp;</tt></font>
<br><font size=2><tt>20 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp;2 &nbsp; &nbsp;
&nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;T &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0 1</tt></font>
<br><font size=2><tt>20 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;2 &nbsp; &nbsp; &nbsp; &nbsp;3 &nbsp; &nbsp;
&nbsp; &nbsp;1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;T &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0 1 1</tt></font>
<br><font size=2><tt>20 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;4 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;3 &nbsp; &nbsp; &nbsp; &nbsp;5 &nbsp; &nbsp;
&nbsp; &nbsp;2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;T &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0 1 1 2</tt></font>
<br><font size=2><tt>20 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;5 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;5 &nbsp; &nbsp; &nbsp; &nbsp;8 &nbsp; &nbsp;
&nbsp; &nbsp;3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;5 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;T &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0 1 1 2 3</tt></font>
<br><font size=2><tt>20 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;6 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;8 &nbsp; &nbsp; &nbsp; &nbsp;13 &nbsp; &nbsp;
&nbsp; &nbsp;5 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;8 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;T &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0 1 1 2 3 5</tt></font>
<br><font size=2><tt>.</tt></font>
<br><font size=2><tt>.</tt></font>
<br><font size=2><tt>.</tt></font>
<br><font size=2><tt>20 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;19 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;2584 &nbsp; &nbsp; &nbsp; &nbsp;6765 &nbsp;
&nbsp; &nbsp; &nbsp;4181 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;2584 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;T &nbsp;
&nbsp; &nbsp; &nbsp;0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610
987 1597 2584 4181</tt></font>
<br><font size=2><tt>20 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;20 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp;2584 &nbsp; &nbsp; &nbsp; &nbsp;6765 &nbsp;
&nbsp; &nbsp; &nbsp;4181 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp;2584 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;F &nbsp;
&nbsp; &nbsp; &nbsp;0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610
987 1597 2584 4181 &nbsp; &nbsp; &nbsp; &nbsp;</tt></font>
<br><font size=2><tt>(You might want to check the last two rows, not guaranteeing
the values are right)</tt></font>
<br>
<br><font size=2><tt>In the last row count&lt;max_count is False the loop
won't run and therefore nothing will change. </tt></font>
<br>
<br><font size=2><tt>Hope this helps some, but would recommend you try
following some of the tutorials online for beginning programming to help
explain some of the concepts, feel free to ask here whenever you get confused.</tt></font>
<br>
<br><font size=2><tt>&nbsp; </tt></font>
<br><font size=2><tt>Chris</tt></font>
<br><font size=2><tt>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; </tt></font>