简体   繁体   中英

Why isn't there a do while flow control statement in python?

Is there a good reason why there isn't a do while flow control statement in python?

Why do people have to write while and break explicitly?

它已在PEP 315中提出,但尚未实现,因为没有人提出一种语法比使用内部if-breakwhile True更清晰。

Probably because Guido didn't think it was necessary. There are a bunch of different flow-control statements you could support, but most of them are variants of each other. Frankly, I've found the do-while statement to be one of the less useful ones.

因为那时你有两种方法可以做某事。

Python adds features only when they significantly simplify some code.

while True:
    ...
    if not cond: break

is not less simple than a do-while loop, for which there is no obvious natural python syntax anyway.

do:
    ...
    while cond

(Looks weird)

or this?

do:
    ...
while cond

(The while looks like a regular while statement)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM