[issue481118] 'switch'/'case'/'else' statement

2022-04-10 Thread admin
Change by admin : -- github: None -> 35514 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

Re: Else statement executing when it shouldnt

2013-01-25 Thread Frank Millman
On 23/01/2013 15:35, Jussi Piitulainen wrote: Thomas Boell writes: Using a keyword that has a well-understood meaning in just about every other programming language on the planet *and even in English*, redefining it to mean something completely different, and then making the syntax look like

Re: Else statement executing when it shouldnt

2013-01-23 Thread Thomas Boell
On Tue, 22 Jan 2013 17:28:35 -0800 (PST) alex23 wuwe...@gmail.com wrote: On Jan 23, 1:48 am, Thomas Boell tbo...@domain.invalid wrote: I must say, that's bound to be confusing for anyone who knows any language other than Python (or none, even).  Syntax like that is an accident waiting to

Re: Else statement executing when it shouldnt

2013-01-23 Thread Jussi Piitulainen
Thomas Boell writes: Using a keyword that has a well-understood meaning in just about every other programming language on the planet *and even in English*, redefining it to mean something completely different, and then making the syntax look like the original, well-understood meaning --

Re: Else statement executing when it shouldnt

2013-01-23 Thread Jerry Hill
On Wed, Jan 23, 2013 at 8:35 AM, Jussi Piitulainen jpiit...@ling.helsinki.fi wrote: The feature isn't bad, it's just very, very badly named. I believe it would read better - much better - if it was for/then and while/then instead of for/else and while/else. That's always been my opinion too.

Re: Else statement executing when it shouldnt

2013-01-22 Thread Thomas Boell
On Mon, 21 Jan 2013 06:07:08 +0100 René Klačan rene.kla...@gmail.com wrote: Examples: # else branch will be executed i = 0 while i 5: i += 1 else: print('loop is over') # else branch will be executed i = 0 while i 5: i += 1 if i == 7: print('i == 7')

Re: Else statement executing when it shouldnt

2013-01-22 Thread Chris Angelico
On Wed, Jan 23, 2013 at 2:39 AM, Thomas Boell tboell@domain.invalid wrote: Huh?! I would have expected all your examples to raise a SyntaxError or IndentationError. Why don't they? Is 'else' not required to have a matching 'if'? Other things can have else, including 'for' and 'while' loops. :)

Re: Else statement executing when it shouldnt

2013-01-22 Thread Duncan Booth
Thomas Boell tboell@domain.invalid wrote: Huh?! I would have expected all your examples to raise a SyntaxError or IndentationError. Why don't they? Is 'else' not required to have a matching 'if'? Matching 'if' or 'for' or 'while'. See

Re: Else statement executing when it shouldnt

2013-01-22 Thread Duncan Booth
Duncan Booth duncan.booth@invalid.invalid wrote: Matching 'if' or 'for' or 'while'. or of course 'try'. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Else statement executing when it shouldnt

2013-01-22 Thread Thomas Boell
On Wed, 23 Jan 2013 02:42:27 +1100 Chris Angelico ros...@gmail.com wrote: On Wed, Jan 23, 2013 at 2:39 AM, Thomas Boell tboell@domain.invalid wrote: Huh?! I would have expected all your examples to raise a SyntaxError or IndentationError. Why don't they? Is 'else' not required to have a

Re: Else statement executing when it shouldnt

2013-01-22 Thread Chris Angelico
On Wed, Jan 23, 2013 at 2:48 AM, Thomas Boell tboell@domain.invalid wrote: On Wed, 23 Jan 2013 02:42:27 +1100 Chris Angelico ros...@gmail.com wrote: On Wed, Jan 23, 2013 at 2:39 AM, Thomas Boell tboell@domain.invalid wrote: Huh?! I would have expected all your examples to raise a SyntaxError

Re: Else statement executing when it shouldnt

2013-01-22 Thread Steven D'Aprano
` block *unconditionally* executes after the `for` block. The only way to skip it is to use `break`, which skips all the way out of the combined for...else statement. This is a very useful feature, very badly named. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Else statement executing when it shouldnt

2013-01-22 Thread René Klačan
in sequence: do_something_with(x) if condition: break else: print condition was never true That's right. The `else` block *unconditionally* executes after the `for` block. The only way to skip it is to use `break`, which skips all the way out of the combined for...else

Re: Else statement executing when it shouldnt

2013-01-22 Thread alex23
On Jan 23, 1:48 am, Thomas Boell tbo...@domain.invalid wrote: I must say, that's bound to be confusing for anyone who knows any language other than Python (or none, even).  Syntax like that is an accident waiting to happen... No, ignorantly expecting every language to conform to every other is

Re: Else statement executing when it shouldnt

2013-01-21 Thread Steven D'Aprano
On Sun, 20 Jan 2013 22:00:10 -0800, alex23 wrote: On Jan 21, 2:54 pm, eli m techgeek...@gmail.com wrote: hint: Use the comments in the code to find out where my error is. Pro-tip: when people you're asking for help tell you how you can make it easier for them to help you, a snide response

Re: Else statement executing when it shouldnt

2013-01-21 Thread eli m
On Sunday, January 20, 2013 9:56:59 PM UTC-8, alex23 wrote: On Jan 21, 2:40 pm, eli m techgeek...@gmail.com wrote: an else statement is running when it shouldnt be. It is on the last line. Whenever i am in the math or game function, when i type in main, it goes back to the start

Re: Else statement executing when it shouldnt

2013-01-21 Thread Chris Angelico
On Tue, Jan 22, 2013 at 2:37 AM, eli m techgeek...@gmail.com wrote: Thank you, that solved my problem. Sorry for my posts, i am a noob and this is my first time posting on here. There's nothing wrong with being a noob, we all start out that way. Want to be one of the people we love to help?

Re: Else statement executing when it shouldnt

2013-01-20 Thread Roy Smith
In article 2cc6791f-ba56-406c-a5b0-b23023caf...@googlegroups.com, eli m techgeek...@gmail.com wrote: an else statement is running when it shouldnt be. It is on the last line. Whenever i am in the math or game function, when i type in main, it goes back to the start of the program

Re: Else statement executing when it shouldnt

2013-01-20 Thread Chris Angelico
On Mon, Jan 21, 2013 at 3:40 PM, eli m techgeek...@gmail.com wrote: an else statement is running when it shouldnt be. It is on the last line. Whenever i am in the math or game function, when i type in main, it goes back to the start of the program, but it also says not a valid function. I am

Re: Else statement executing when it shouldnt

2013-01-20 Thread eli m
On Sunday, January 20, 2013 8:54:13 PM UTC-8, René Klačan wrote: You have to break while loop not to execute else branch Rene Can you explain in more detail please. -- http://mail.python.org/mailman/listinfo/python-list

Re: Else statement executing when it shouldnt

2013-01-20 Thread René Klačan
You have to break while loop not to execute else branch Rene On Mon, Jan 21, 2013 at 5:40 AM, eli m techgeek...@gmail.com wrote: an else statement is running when it shouldnt be. It is on the last line. Whenever i am in the math or game function, when i type in main, it goes back

Re: Else statement executing when it shouldnt

2013-01-20 Thread eli m
Your else is lined up with while, not with if. -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ When a friend succeeds, I die a little. Gore Vidal Its lined up. It got messed up when i copied the code into the post. --

Re: Else statement executing when it shouldnt

2013-01-20 Thread eli m
On Sunday, January 20, 2013 8:40:47 PM UTC-8, eli m wrote: hint: Use the comments in the code to find out where my error is. Here is my code: #Cmd #Created By Eli M. #import modules import random import math gtn = 0 print (Type in help for a list of cmd functions)

Re: Else statement executing when it shouldnt

2013-01-20 Thread eli m
On Sunday, January 20, 2013 8:52:12 PM UTC-8, Chris Angelico wrote: On Mon, Jan 21, 2013 at 3:40 PM, eli m techgeek...@gmail.com wrote: an else statement is running when it shouldnt be. It is on the last line. Whenever i am in the math or game function, when i type in main, it goes back

Re: Else statement executing when it shouldnt

2013-01-20 Thread Mitya Sirenef
On 01/20/2013 11:40 PM, eli m wrote: an else statement is running when it shouldnt be. It is on the last line. Whenever i am in the math or game function, when i type in main, it goes back to the start of the program, but it also says not a valid function. I am stumped! Here is my code

Re: Else statement executing when it shouldnt

2013-01-20 Thread René Klačan
Examples: # else branch will be executed i = 0 while i 5: i += 1 else: print('loop is over') # else branch will be executed i = 0 while i 5: i += 1 if i == 7: print('i == 7') break else: print('loop is over') # else branch wont be executed i = 0 while i

Re: Else statement executing when it shouldnt

2013-01-20 Thread René Klačan
Examples: # else branch will be executed i = 0 while i 5: i += 1 else: print('loop is over') # else branch will be executed i = 0 while i 5: i += 1 if i == 7: print('i == 7') break else: print('loop is over') # else branch wont be executed i = 0 while i

Re: Else statement executing when it shouldnt

2013-01-20 Thread alex23
On Jan 21, 2:59 pm, eli m techgeek...@gmail.com wrote: Its lined up. It got messed up when i copied the code into the post. Sorry, we're not going to take your word for it. Reduce it to the minimal amount of code that reproduces your error and post that. --

Re: Else statement executing when it shouldnt

2013-01-20 Thread alex23
On Jan 21, 2:40 pm, eli m techgeek...@gmail.com wrote: an else statement is running when it shouldnt be. It is on the last line. Whenever i am in the math or game function, when i type in main, it goes back to the start of the program, but it also says not a valid function. I am stumped

Re: Else statement executing when it shouldnt

2013-01-20 Thread alex23
On Jan 21, 2:54 pm, eli m techgeek...@gmail.com wrote: hint: Use the comments in the code to find out where my error is. Pro-tip: when people you're asking for help tell you how you can make it easier for them to help you, a snide response isn't the correct approach. --

Re: Else statement executing when it shouldnt

2013-01-20 Thread Mitya Sirenef
On 01/20/2013 11:59 PM, eli m wrote: Your else is lined up with while, not with if. -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ When a friend succeeds, I die a little. Gore Vidal Its lined up. It got messed up when i copied the code into the post. I

Re: Finding the line number of an 'else' statement via ast

2012-05-11 Thread Mark Lawrence
On 11/05/2012 05:35, Michael Rene Armida wrote: Given this source: def do_something(val): if val: return 'a' else: return 'b' How do I get the line number of the else: line, using the ast module? The grammar only includes the 'orelse' list: If(expr test,

Re: Finding the line number of an 'else' statement via ast

2012-05-11 Thread Terry Reedy
On 5/11/2012 12:35 AM, Michael Rene Armida wrote: Given this source: def do_something(val): if val: return 'a' else: return 'b' How do I get the line number of the else: line, using the ast module? The grammar only includes the 'orelse' list: If(expr test,

Finding the line number of an 'else' statement via ast

2012-05-10 Thread Michael Rene Armida
Given this source: def do_something(val): if val: return 'a' else: return 'b' How do I get the line number of the else: line, using the ast module? The grammar only includes the 'orelse' list: If(expr test, stmt* body, stmt* orelse) ...but 'orelse' is the list of

strange behaviour with while-else statement

2011-03-07 Thread Victor Paraschiv
Hi and please help me understand if it is a bug, or..,as someone said, there's a 'bug' in my understanding: (Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on win32) (windows vista, the regular windows python installer) It's about the following code: while True: s

Re: strange behaviour with while-else statement

2011-03-07 Thread Terry Reedy
On 3/7/2011 11:43 AM, Victor Paraschiv wrote: Hi and please help me understand if it is a bug, or..,as someone said, there's a 'bug' in my understanding: (Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on win32) (windows vista, the regular windows python installer)

Re: if-else statement

2009-01-11 Thread Aaron Brady
On Jan 10, 2:28 pm, bearophileh...@lycos.com wrote: Scott David Daniels:       if checking:           my_var = 'string'       else:           my_var = 'other string' remember, vertical space only kills trees if printed. I value clarity a lot. But this is more DRY, sometimes it's

if-else statement

2009-01-10 Thread Gandalf
other languages like PHP or javascript as this if-else operator like this myVar = checking == 1? 'string': 'other string' is this stuff exist in python? thanks! -- http://mail.python.org/mailman/listinfo/python-list

Re: if-else statement

2009-01-10 Thread Duncan Booth
Gandalf goldn...@gmail.com wrote: other languages like PHP or javascript as this if-else operator like this myVar = checking == 1? 'string': 'other string' is this stuff exist in python? See http://docs.python.org/reference/expressions.html#boolean-operations conditional_expression

Re: if-else statement

2009-01-10 Thread Philip Semanchuk
On Jan 10, 2009, at 9:26 AM, Duncan Booth wrote: Gandalf goldn...@gmail.com wrote: other languages like PHP or javascript as this if-else operator like this myVar = checking == 1? 'string': 'other string' is this stuff exist in python? See

Re: if-else statement

2009-01-10 Thread Scott David Daniels
Duncan Booth wrote: Gandalf goldn...@gmail.com wrote: other languages ... [have an] if-else operator like... myVar = checking == 1? 'string': 'other string' See http://docs.python.org/reference/expressions.html#boolean-operations ... The expression x if C else y first evaluates C (not

Re: if-else statement

2009-01-10 Thread bearophileHUGS
Scott David Daniels:       if checking:           my_var = 'string'       else:           my_var = 'other string' remember, vertical space only kills trees if printed. I value clarity a lot. But this is more DRY, sometimes it's almost equally clear, and you reduce vertical space, packing

error in the if, elif, else statement ?

2007-05-09 Thread juan-manuel . behrendt
Hello together, I wrote a script for the engineering software abaqus/CAE. It worked well until I implemented a selection in order to variate the variable lGwU through an if elif, else statement. I am going to post the first 82 lines of the script, since the error message points at line 80: from

Re: error in the if, elif, else statement ?

2007-05-09 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], juan-manuel.behrendt wrote: Hello together, I wrote a script for the engineering software abaqus/CAE. It worked well until I implemented a selection in order to variate the variable lGwU through an if elif, else statement. I am going to post the first 82 lines

Re: error in the if, elif, else statement ?

2007-05-09 Thread John Machin
On May 9, 5:46 pm, [EMAIL PROTECTED] wrote: Hello together, I wrote a script for the engineering software abaqus/CAE. It worked well until I implemented a selection in order to variate the variable lGwU through an if elif, else statement. I am going to post the first 82 lines of the script