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


Groups > comp.lang.python > #110692

RE: Iteration, while loop, and for loop

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From "Joseph Lee" <joseph.lee22590@gmail.com>
Newsgroups comp.lang.python
Subject RE: Iteration, while loop, and for loop
Date Tue, 28 Jun 2016 06:26:30 -0700
Lines 40
Message-ID <mailman.76.1467120399.2358.python-list@python.org> (permalink)
References <079ff112-8f18-4a27-938f-12e4e55a4a5b@googlegroups.com> <CAGgTfkOkhy8HMd2w-hTHMb4K4vsJhAhoAju2y=+c87Fj=ciZRA@mail.gmail.com> <00c301d1d140$af331e10$0d995a30$@gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset="us-ascii"
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de tapciRJXCtpC0lrMR9NbLw2+TAU3D4fwjEyOc1IUZn9w==
Return-Path <joseph.lee22590@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'elegant': 0.07; 'indexing': 0.07; 'part,': 0.09; 'preferable': 0.09; 'subject:while': 0.09; 'python': 0.10; 'message-----': 0.15; '2016': 0.16; 'iteration,': 0.16; 'loops': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'skip:[ 60': 0.16; 'variable.': 0.16; 'wrote:': 0.16; 'input': 0.18; 'assign': 0.22; 'simpler': 0.22; 'cheers,': 0.22; 'code.': 0.23; 'second': 0.24; 'header:In- Reply-To:1': 0.24; 'not.': 0.27; 'actual': 0.28; 'looks': 0.29; 'loop,': 0.29; 'url:wikipedia': 0.29; 'array': 0.29; 'url:wiki': 0.30; 'url:mailman': 0.30; 'code': 0.30; 'version,': 0.30; 'useful': 0.33; 'url:python': 0.33; 'michael': 0.33; 'message- id:@gmail.com': 0.34; 'skip:- 10': 0.34; 'url:listinfo': 0.34; 'tue,': 0.34; 'received:google.com': 0.35; 'sent:': 0.35; 'question,': 0.35; 'something': 0.35; 'subject:': 0.35; 'item': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'url:org': 0.36; '(and': 0.36; 'email addr:python.org': 0.36; 'to:addr:python- list': 0.36; 'subject:: ': 0.37; 'charset:us-ascii': 0.37; 'wanted': 0.37; 'someone': 0.38; 'hi,': 0.38; 'why': 0.39; 'url:en': 0.39; 'from:': 0.39; 'url:mail': 0.40; 'to:addr:python.org': 0.40; 'more': 0.63; 'different': 0.63; 'times': 0.63; 'better.': 0.66; 'python-list': 0.66; 'email name :python-list': 0.67; 'elizabeth': 0.72; 'fragment': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:references:in-reply-to:subject:date:message-id:mime-version :content-transfer-encoding:thread-index:content-language; bh=SMbONemmp2We+mqUiHRxwH0KTGBC5DYWznJ4UGtt0kA=; b=l8U6Ojbk/JeOWd+/Gg+FcvCFo3/Z8d2Ld+WhSR3E2g0UGqoNtBq5JxcR5vJcCI3ZwY IJnKfaB4tOH3qSgSZE/wRjF/pUUdN/7mCmMUEK5CbStqbZb9Lm1RYkaMNmXht/UH2Ztv ve/hlkVZYDXBbfKCE9a7jZBWAs9fKNNBSdSTDaaZZp+21zT7Vawp5o0nNcrmUQ4MDuuk +6vJqG+5UJ30B5QvM1lQwTnFEE1rZ6I5T3khNC+8uSRoECF1AHippoXGYXQ63US0w1vH xXEhSYz4Kk4pNyCklWgJUGjRFMz4oJGWdcrjhP2u9iY5grJpXEyB2tg6zu83KvjuKCQS 3eNg==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:references:in-reply-to:subject:date :message-id:mime-version:content-transfer-encoding:thread-index :content-language; bh=SMbONemmp2We+mqUiHRxwH0KTGBC5DYWznJ4UGtt0kA=; b=iPYZwIXBjEkNhGHlzhGTN2LaJEC/rxvHe5acPv5iyHRn59eqyesEkb/OOsGxwDuMOO L2TIkm2i9QfsxIfl3ui4lO6GCpewgrYeVxhN+d6e71LBt+3PxSzGJptFKa4y7UrRbeRn UYlRhp/2XCeROKzdfN4fm5E3KYeE2mNC7eS6r2TnZiuhMdvnBofSLUsWsUXAI/xX80qe WQStic5T51eyVPqwGVkQwJis2Nt4VtUGvn5ngDrAea4BOMnPhC5pwv1twrxBYY48iZKq BNDOuF11aIS8zk828gCAqO5szlj9QZH87cIFQdFEngdg1l69+tkTlLWYTGqmTLlHtb+J p0Cg==
X-Gm-Message-State ALyK8tLBsalh2ziS897WDKZMDlA5xGRFOllI9bpH6ur+Z+uElJFU4x0Dli95qqFvjHRU5Q==
X-Received by 10.157.11.59 with SMTP id a56mr1772793ota.128.1467120392220; Tue, 28 Jun 2016 06:26:32 -0700 (PDT)
In-Reply-To <CAGgTfkOkhy8HMd2w-hTHMb4K4vsJhAhoAju2y=+c87Fj=ciZRA@mail.gmail.com>
X-Mailer Microsoft Outlook 15.0
Thread-Index AQDNHn+bXXAM/wczACBDRZZDJib4KwJAOAeYofZBnDA=
Content-Language en-us
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <00c301d1d140$af331e10$0d995a30$@gmail.com>
X-Mailman-Original-References <079ff112-8f18-4a27-938f-12e4e55a4a5b@googlegroups.com> <CAGgTfkOkhy8HMd2w-hTHMb4K4vsJhAhoAju2y=+c87Fj=ciZRA@mail.gmail.com>
Xref csiph.com comp.lang.python:110692

Show key headers only | View raw


Hi,
Answers inline.

-----Original Message-----
From: Python-list
[mailto:python-list-bounces+joseph.lee22590=gmail.com@python.org] On Behalf
Of Michael Selik
Sent: Tuesday, June 28, 2016 6:16 AM
To: Elizabeth Weiss <cake240@gmail.com>; python-list@python.org
Subject: Re: Iteration, while loop, and for loop

On Tue, Jun 28, 2016 at 8:41 AM Elizabeth Weiss <cake240@gmail.com> wrote:

> I do not understand the second code. What is counter?
>

It looks like someone wanted to make a loop induction variable.
https://en.wikipedia.org/wiki/Induction_variable

JL: Or access the array item via indexing.

> Why do we use this code if we can use the simpler for loop?
>

You should not. Use the first version, it's much better. Python for-loops
are preferable to while-loops.

JL: Indexing is useful if one wishes to assign something different to the
position represented by container[index]. But if you want a more elegant way
to access the actual object in question, then using the first fragment is
better (and more readable). For the most part, for loops are better, but
there are times when while loops are preferable such as when you don't know
the size of the input beforehand.

Cheers,
Joseph

-
https://mail.python.org/mailman/listinfo/python-list

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


Thread

Iteration, while loop, and for loop Elizabeth Weiss <cake240@gmail.com> - 2016-06-28 05:36 -0700
  Re: Iteration, while loop, and for loop Michael Selik <michael.selik@gmail.com> - 2016-06-28 13:15 +0000
    Re: Iteration, while loop, and for loop BartC <bc@freeuk.com> - 2016-06-28 14:29 +0100
      Re: Iteration, while loop, and for loop Michael Selik <michael.selik@gmail.com> - 2016-06-28 13:58 +0000
      Re: Iteration, while loop, and for loop Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-28 22:58 -0700
  Re: Iteration, while loop, and for loop BartC <bc@freeuk.com> - 2016-06-28 14:24 +0100
  RE: Iteration, while loop, and for loop "Joseph Lee" <joseph.lee22590@gmail.com> - 2016-06-28 06:26 -0700
  Re: Iteration, while loop, and for loop Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-06-28 16:42 +0300
  Re: Iteration, while loop, and for loop Michael Selik <michael.selik@gmail.com> - 2016-06-28 13:51 +0000
  Re: Iteration, while loop, and for loop Steven D'Aprano <steve@pearwood.info> - 2016-06-29 01:20 +1000
    Re: Iteration, while loop, and for loop Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-06-28 18:28 +0300
    Re: Iteration, while loop, and for loop Tim Chase <python.list@tim.thechases.com> - 2016-06-28 12:23 -0500
    Re: Iteration, while loop, and for loop Grant Edwards <grant.b.edwards@gmail.com> - 2016-06-28 17:58 +0000
    Re: Iteration, while loop, and for loop Ian Kelly <ian.g.kelly@gmail.com> - 2016-06-29 09:29 -0600
      Re: Iteration, while loop, and for loop Steven D'Aprano <steve@pearwood.info> - 2016-06-30 09:59 +1000
        Re: Iteration, while loop, and for loop Tim Chase <python.list@tim.thechases.com> - 2016-06-30 05:44 -0500
        Re: Iteration, while loop, and for loop Ian Kelly <ian.g.kelly@gmail.com> - 2016-06-30 07:04 -0600
        Re: Iteration, while loop, and for loop Ian Kelly <ian.g.kelly@gmail.com> - 2016-06-30 07:10 -0600
        Re: Iteration, while loop, and for loop jfong@ms4.hinet.net - 2016-06-30 19:12 -0700
  Re: Iteration, while loop, and for loop Veek M <vek.m1234@gmail.com> - 2016-10-27 14:35 +0530

csiph-web