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


Groups > comp.lang.python > #52190

Re: beginner question (True False help)

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'subject:help': 0.08; 'exception,': 0.09; 'exit': 0.09; 'thrown': 0.09; 'subject:question': 0.10; 'def': 0.12; '"if"': 0.16; 'cmp': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'jmp': 0.16; 'redundant.': 0.16; 'return,': 0.16; 'subject:beginner': 0.16; 'true:': 0.16; 'followed': 0.16; 'language': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'programming': 0.22; 'aug': 0.22; 'putting': 0.22; 'looks': 0.24; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; '>>>>': 0.31; 'minor': 0.31; 'level.': 0.33; 'maybe': 0.34; 'could': 0.34; 'subject: (': 0.35; 'something': 0.35; 'etc': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'branch': 0.38; 'to:addr:python- list': 0.38; 'though,': 0.39; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'letters': 0.60; 'break': 0.61; 'personal': 0.63; 'etc),': 0.84; 'subject:True': 0.91; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=N5r9ZKSukd2nRk9MMebUim4p2LthihxucHP/XujJr2A=; b=pnlAB9AdK+ApRKsFoniHmcLcyXKM043s+zIkxDVa/pmZc8iIEBZrMETApOZUXyXgqK DCieYlowKAz6eKQOtAsQIiRsUjkvRM3twBrpbGPwc4mNROIYlqDqpW7YOGow5FgObltS 4HrtYW3QVBwuHls64LxqR5UwfQxpC6j7fL3tNK1uX8JYhllqfcT2Gcrea359gtijbouP yNP+nH9pPmGGPxG4sa8z0hBjqVjt8yIdqPdjgFZVwu5sVZHD+PH1JCD9WLjs6V9ywbQl 4K+AXw80g/zJv4otVvFr0X0wC46Vn2G8Z6dvqvgvFfYffTDWPOBmiHfbgVAuLe3b5a5l o41A==
MIME-Version 1.0
X-Received by 10.220.169.146 with SMTP id z18mr3708980vcy.80.1375962110938; Thu, 08 Aug 2013 04:41:50 -0700 (PDT)
In-Reply-To <72cd8537-7494-48d6-a58a-a50a319d8e2a@googlegroups.com>
References <6c6dedec-5e47-4229-bc67-01b058cdb410@googlegroups.com> <72cd8537-7494-48d6-a58a-a50a319d8e2a@googlegroups.com>
Date Thu, 8 Aug 2013 12:41:50 +0100
Subject Re: beginner question (True False help)
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.348.1375962120.1251.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1375962120 news.xs4all.nl 15892 [2001:888:2000:d::a6]:46337
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:52190

Show key headers only | View raw


On Thu, Aug 8, 2013 at 7:20 AM,  <wxjmfauth@gmail.com> wrote:
>>>> def z2():
> ...     letters = 'abc'
> ...     while True:
> ...         c = input('letter: ')
> ...         if c not in letters:
> ...             print('end, fin, Schluss')
> ...             break
> ...         else:
> ...             print('do stuff')


Minor quibble: I don't like having a hard exit followed by an "else".
If the "if" branch will unconditionally quit the loop (with a break,
here, but could also be a return, a thrown exception, etc etc), I
would prefer to see the "else" removed and its code unindented one
level. Maybe this is just personal preference, though, learned from
assembly language programming where a "block if" looks something like
this:

; if x == y:
CMP x,y
JNZ .else
; Code for "x == y"
JMP .endif
.else:
; Code for "else"
.endif

Putting an unconditional departure in the "x == y" branch makes the
"JMP .endif" redundant.

ChrisA

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


Thread

beginner question (True False help) eschneider92@comcast.net - 2013-08-07 01:17 -0700
  Re: beginner question (True False help) Joshua Landau <joshua@landau.ws> - 2013-08-07 09:42 +0100
  Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-07 13:59 -0700
    Re: beginner question (True False help) Dave Angel <davea@davea.name> - 2013-08-08 01:18 +0000
  Re: beginner question (True False help) Larry Hudson <orgnut@yahoo.com> - 2013-08-07 19:49 -0700
  Re: beginner question (True False help) wxjmfauth@gmail.com - 2013-08-07 23:20 -0700
    Re: beginner question (True False help) Chris Angelico <rosuav@gmail.com> - 2013-08-08 12:41 +0100
    Re: beginner question (True False help) Terry Reedy <tjreedy@udel.edu> - 2013-08-08 16:29 -0400
      Re: beginner question (True False help) wxjmfauth@gmail.com - 2013-08-09 01:05 -0700
  Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 15:27 -0700
    Re: beginner question (True False help) Joshua Landau <joshua@landau.ws> - 2013-08-10 00:05 +0100
    Re: beginner question (True False help) Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-08-09 22:58 -0400
  Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 15:28 -0700
  Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 16:14 -0700
    Re: beginner question (True False help) Joshua Landau <joshua@landau.ws> - 2013-08-10 00:30 +0100
  Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 16:24 -0700
  Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 16:34 -0700
    Re: beginner question (True False help) Joshua Landau <joshua@landau.ws> - 2013-08-10 02:22 +0100
    Re: beginner question (True False help) Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-10 01:40 +0000
  Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 16:40 -0700
    Re: beginner question (True False help) MRAB <python@mrabarnett.plus.com> - 2013-08-10 01:39 +0100
  Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 16:43 -0700
  Re: beginner question (True False help) eschneider92@comcast.net - 2013-08-09 18:08 -0700

csiph-web