[Python-bugs-list] [ python-Bugs-462937 ] continue inside try confuses while loop

noreply@sourceforge.net noreply@sourceforge.net
Wed, 19 Sep 2001 10:50:26 -0700


Bugs item #462937, was opened at 2001-09-19 10:46
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=462937&group_id=5470

Category: Python Interpreter Core
Group: Python 2.1.1
Status: Open
Resolution: None
Priority: 5
Submitted By: Amit Patel (amitp)
Assigned to: Nobody/Anonymous (nobody)
Summary: continue inside try confuses while loop

Initial Comment:
If there's a continue inside a try inside a while with
a break inside a function, well, things go wacky.  I'll
post code and give a description:

#!/usr/bin/env python2

def bug(n):
  print 'Top'
  x = 0
  while 1:
    print 'x = %d' % x
    x = x + 1
    if x > n: break
    try:
      y = float(42)
      if y > 10:
        continue
    except ValueError:
      print 'Error'
  print 'Bottom'

bug(4)  # no loop
bug(3)  # loops



When you run bug(4), it does what you expect -- prints
Top, prints x= for various values of x, then prints
Bottom, and returns.

When you run bug(3), it prints Top, various values of
x, and then instead of 'break' getting out of the loop,
it jumps to the top of the function and prints Top again !!

This seems really weird to me.  Odd values of n behave
differently than even values of n !



----------------------------------------------------------------------

>Comment By: Amit Patel (amitp)
Date: 2001-09-19 10:50

Message:
Logged In: YES 
user_id=327765

Bah, it destroyed my formatting.  I'll upload a separate file.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=462937&group_id=5470