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

noreply@sourceforge.net noreply@sourceforge.net
Wed, 19 Sep 2001 21:50:32 -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: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Amit Patel (amitp)
>Assigned to: Thomas Wouters (twouters)
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: Guido van Rossum (gvanrossum)
Date: 2001-09-19 21:50

Message:
Logged In: YES 
user_id=6380

I can reproduce this in 2.2 too.  Thomas, can you look at
this? I believe you wrote the continue-in-try code...

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

Comment By: Gerhard Häring (ghaering)
Date: 2001-09-19 19:42

Message:
Logged In: YES 
user_id=163326

FYI: Python 1.5.2 and 2.0.1 say:

gerhard@lilith:/tmp > /opt/python20/bin/python 
python-continue-bug-2.py
SyntaxError: 'continue' not supported inside 'try' clause 
(python-continue-bug-2.py, line 10)

This problem seems to have started with the 2.1 branch.


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

Comment By: Amit Patel (amitp)
Date: 2001-09-19 13:18

Message:
Logged In: YES 
user_id=327765

I'm attaching a variant of the program which runs and then
causes "SystemError: unknown opcode".


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

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