Loop-and-a-half (Re: Curious assignment behaviour)
Jeff Shannon
jeff at ccvcorp.com
Fri Oct 12 19:55:04 EDT 2001
>
> That's because there are two breaks that have different semantical meanings.
> The fully equivalent version in today's syntax has to use one extra variable
> (assuming the variable _flag is not used for other purpose):
Nope. (see below)
>
>
> _flag = 0
> while 1:
> x = next()
> if x.is_end: break
> y = process(x)
> if y.is_what_we_are_looking_for():
> _flag = 1
> break
> if not _flag:
> raise "not found"
> del _flag
>
while 1:
x = next()
if x.is_end(): break
y = process(x)
if not y.is_good_result():
raise "not found"
Personally, I think that the construct you are promoting,
while (expression); (condition):
(suite)
.... is ugly and non-intuitive, and I would *not* want to use it. Just my
opinion, but.....
Jeff Shannon
Technician/Programmer
Credit International
More information about the Python-list
mailing list