Re: Another newbee question
Guido.van.Rossum@cwi.nl
Mon, 11 Apr 1994 16:56:18 +0200
> I get the following error from the following code
> SyntaxError: 'continue' not properly in loop
> I want to go back the next line in the for loop, that's all!
> I've looked at other code were this construct is used, I'm sure my problem
> is subtle.
>
> ...
> file = open(filename,'r')
> for line in file.readlines():
> fields = string.split(line)
> try:
> if fields[3] == 'IN:' :
> pass
> elif fields[3] == 'OUT:' :
> pass
> else:
> print 'Next'
> --------> continue
> prodkey = fields[4] + fields[2]
> ...
You don't say it, but I suspect that your try clause is part of a
try-finally statement. There is a prohibition for continue to pass
control out of the try clause of a try-finally statement (stated in
the reference manual). The reason is that it isn't clear whether
you'd want the finally clause to be executed or not in this case
(since you jump backward, not forward).
I leave the possible work-arounds to the readership...
--Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
URL: <http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>