[New-bugs-announce] [issue1920] while else loop seems to behave incorrectly

Mark Summerfield report at bugs.python.org
Thu Jan 24 14:22:49 CET 2008


New submission from Mark Summerfield:

I am using:

Python 3.0a2 (r30a2:59382, Dec 17 2007, 08:47:22) 
[GCC 4.1.2 20070626 (Red Hat 4.1.2-13)] on linux2
IDLE 3.0a1 

This seems wrong:

>>> while False:
	print("no")
else:
	print("yes")

	
>>> 

I expected it to print "yes" because the docs say that the else suite is
executed if present and if the loop terminated normally (no break), and
this is the case here.

This works though:

>>> x = False
>>> while x:
	print("no")
else:
	print("yes")

	
yes
>>> 

So it seems that "while False" and "while variable" are giving different
behaviour.

----------
components: Interpreter Core
messages: 61629
nosy: mark
severity: normal
status: open
title: while else loop seems to behave incorrectly
type: behavior
versions: Python 3.0

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1920>
__________________________________


More information about the New-bugs-announce mailing list