while (a=b()) ...

Donn Cave donn at u.washington.edu
Fri May 14 12:20:04 EDT 1999


Greg Ewing <greg.ewing at compaq.com> writes:
| "Evan Simpson" <evan at tokenexchange.com> writes:
|| This has been suggested (and Guido has said that he might well put it in) as
|| "and while"
||
|| while 1:
||   value = getValue()
|| and while value:
||   process(value)
|
| I've been thinking for quite a while about how best to 
| phrase such a construct so as to minimise mangulation
| of English, and so far my best effort is:
|
|   while:
|     <suite>
|   gives <bool-expr>:
|     <suite>
|
| for example:
|
|   while:
|     line = f.readline()
|   gives line <> "":
|     frobulate(line)
|
| Requires a new keyword... maybe in Python 2?

Worried about mangulation of English, eh?

To my eye that wants to tie the condition to the immediately preceding
assignment - would

    while:
      line = f.readline()
      lineno = lineno + 1
      print 'line', lineno, 'read', len(line), 'chars'
    gives line:
      frobulate(line)

be legal?

I like the generality of an exit anywhere, so I hope it would.  But
then I also appreciate the fact that I can already do this with "break",
without introducing the novelty of an outdent within a block.  (And
another nice thing about "break" is its symmetrical companion control
"continue".  Give them a respelling for break, and next they'll want
another keyword for continue.)

The part I really like the best is "while:".  There's some hope in my
mind that it could ease the suffering and shame of the folks who are
too cool to say "while 1:" comfortably.  There might be some broader
mileage in the construct, for example "for i:" might be taken to mean
"for i in range(INF):", which is a little awkward in the current
language (best I can do is  "i = 0;  while 1: i = i + 1; ...")

	Donn Cave, University Computing Services, University of Washington
	donn at u.washington.edu




More information about the Python-list mailing list