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: 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Thu, Aug 8, 2013 at 7:20 AM, 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