A single, general looping construct? (was: why no "do : until"?)
Rainer Deyke
root at rainerdeyke.com
Tue Jan 9 17:21:13 EST 2001
"Steve Holden" <sholden at holdenweb.com> wrote in message
news:HxL66.2499$24.24441 at e420r-atl2.usenetserver.com...
> Also, in both your original example and my extension, the final "while"
> statement has a condition which isn't really a Boolean. You appear to mean
> "as long as a particular exception has not been raised", but exceptions
> don't really work like that. You would end up having to clear a flag
before
> the loop, and set it when the exception occurs:
>
> flag = 0
> try:
> filename = raw_input('Data file: ')
> f = open(filename, 'r')
> # Process the file
> except IOError:
> print "Could not open file", filename
> flag = 1
> while not flag
>
> which does not seem to be a real improvement over
>
> flag = 0
> while not flag:
> try:
> filename = raw_input('Data file: ')
> f = open(filename, 'r')
> # Process the file
> except IOError:
> print "Could not open file", filename
> flag = 1
Even better:
try:
while 1:
filename = raw_input('Data file: ')
f = open(filename, 'r')
# Process the file
except IOError:
print "Could not open file", filename
--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor
More information about the Python-list
mailing list