do ... while loop

Alexander Williams thantos at brimstone.mecha
Wed Oct 13 21:06:31 EDT 1999


On 14 Oct 1999 00:11:55 GMT, Joshua Marcus <josh at linc.cis.upenn.edu> wrote:
>What is the %$*&@#!@ rationale behind not including a do...while control 
>structure in Python?
>
>I know you can simply work around it, e.g:
>
>line = "foo"
>while input != "":
>    line = fp.readline()
>    process(line)
>
>... but why must I do this every time?  Am I missing something?

Yes, you're missing three things:

  1) That initalization line should be "line = fp.readline()"
  2) "input" should be "line" in the while check.
  3) Python is designed to minimize the syntactic sugar poured in the
gas-tank of your coding; "do ... while" truly is only a syntactic
abstraction for an initialized while loop (as my professor was kind
enough to teach us long ago in a basics of CompSci class; in fact most
control structures reduce to one or two axiomatic ones).  Its not that
much more typing, the test is very clearly marked at the top of the
structure, and we have the benefit of a single, consistant means of
presenting the loop rather than thirteen varying ones.

-- 
Alexander Williams (thantos at gw.total-web.net)
"In the end ... Oblivion Always Wins."




More information about the Python-list mailing list