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 th

Re: Else statement executing when it shouldnt

2013-01-23 Thread Jerry Hill
On Wed, Jan 23, 2013 at 8:35 AM, Jussi Piitulainen 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. I'd remember

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 Thomas Boell
On Tue, 22 Jan 2013 17:28:35 -0800 (PST) alex23 wrote: > On Jan 23, 1:48 am, Thomas Boell 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 e

Re: Else statement executing when it shouldnt

2013-01-22 Thread alex23
On Jan 23, 1:48 am, Thomas Boell 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 the pending acci

Re: Else statement executing when it shouldnt

2013-01-22 Thread René Klačan
it seems that lot of you are forgeting about this case: for i in [1,2,3,4,5]: print i else: print('this will be printed also because cycle wasnt broke') so the one case when else branch is executed is when condition is not satisfied and the other case is when there is no break executed du

Re: Else statement executing when it shouldnt

2013-01-22 Thread Steven D'Aprano
On Tue, 22 Jan 2013 16:48:35 +0100, Thomas Boell wrote: > On Wed, 23 Jan 2013 02:42:27 +1100 > Chris Angelico wrote: > >> On Wed, Jan 23, 2013 at 2:39 AM, Thomas Boell >> wrote: >> > Huh?! I would have expected all your examples to raise a SyntaxError >> > or IndentationError. Why don't they? I

Re: Else statement executing when it shouldnt

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

Re: Else statement executing when it shouldnt

2013-01-22 Thread Thomas Boell
On Wed, 23 Jan 2013 02:42:27 +1100 Chris Angelico wrote: > On Wed, Jan 23, 2013 at 2:39 AM, Thomas Boell 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

Re: Else statement executing when it shouldnt

2013-01-22 Thread Duncan Booth
Duncan Booth 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 Duncan Booth
Thomas Boell 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 http://docs.python.org/2/tutorial/controlflow.html#break-and-continue-sta

Re: Else statement executing when it shouldnt

2013-01-22 Thread Chris Angelico
On Wed, Jan 23, 2013 at 2:39 AM, Thomas Boell 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. :) ChrisA -- http:/

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 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-21 Thread Chris Angelico
On Tue, Jan 22, 2013 at 2:37 AM, eli m 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? Here are some tips: h

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 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 pro

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 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

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 wh

Re: Else statement executing when it shouldnt

2013-01-20 Thread alex23
On Jan 21, 2:54 pm, eli m 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. -- http://mail.python.org/mailman/listinfo/pytho

Re: Else statement executing when it shouldnt

2013-01-20 Thread alex23
On Jan 21, 2: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 your code wi

Re: Else statement executing when it shouldnt

2013-01-20 Thread alex23
On Jan 21, 2:59 pm, eli m 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. -- http://mail.python.org/mailman/listinfo/python-list

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 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: > #C

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 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-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 fun

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. -- ht

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 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, b

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 Chris Angelico
On Mon, Jan 21, 2013 at 3: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! Check

Re: Else statement executing when it shouldnt

2013-01-20 Thread Roy Smith
In article <2cc6791f-ba56-406c-a5b0-b23023caf...@googlegroups.com>, 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 val

Else statement executing when it shouldnt

2013-01-20 Thread eli m
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: #Cmd #Created By Eli M. #import modules impo