Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #110288

Re: while Loops

From Ben Finney <ben+python@benfinney.id.au>
Newsgroups comp.lang.python
Subject Re: while Loops
Date 2016-06-22 14:02 +1000
Message-ID <mailman.25.1466568307.11516.python-list@python.org> (permalink)
References <0cf9a94e-b84c-460d-b03d-edf6a941adc0@googlegroups.com> <85twglx45g.fsf@benfinney.id.au>

Show all headers | View raw


Elizabeth Weiss <cake240@gmail.com> writes:

> Why is one of the results 5 since i=i+1?

What do you think ‘i = i + 1’ means? (Asking because your idea of what
that means may be affecting how you expect the loop to behave.)

> Should the maximum result be 4 since 4 +1=5?

Try “thinking like the computer”: perform the steps yourself, reading
each statement as though you are the computer. Keep a pad and pencil at
hand, and make notes on what changes as you go through. See what
you-as-computer actually emit onto the paper, and see whether that
matches what the Python session produces.

-- 
 \      “The difference between a moral man and a man of honor is that |
  `\   the latter regrets a discreditable act, even when it has worked |
_o__)                   and he has not been caught.” —Henry L. Mencken |
Ben Finney

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

while Loops Elizabeth Weiss <cake240@gmail.com> - 2016-06-21 20:50 -0700
  Re: while Loops Wildman <best_lay@yahoo.com> - 2016-06-21 23:04 -0500
  Re: while Loops Rustom Mody <rustompmody@gmail.com> - 2016-06-21 21:04 -0700
  Re: while Loops Ben Finney <ben+python@benfinney.id.au> - 2016-06-22 14:02 +1000
  Re: while Loops Michael Torrie <torriem@gmail.com> - 2016-06-21 22:11 -0600
  Re: while Loops alister <alister.ware@ntlworld.com> - 2016-06-22 08:37 +0000
  Re: while Loops John Gordon <gordon@panix.com> - 2016-06-22 16:03 +0000

csiph-web