coconut icon indicating copy to clipboard operation
coconut copied to clipboard

Add do-while loops

Open evhub opened this issue 5 years ago • 4 comments

Possible syntaxes:

do:
    ...
while cond
do while cond:
    ...
do:
    ...
while: cond

Regardless, they should be compiled to:

while True:
    ...
    if not (cond):
        break

evhub avatar Apr 15 '21 05:04 evhub

FWIW, the third syntax does not seem "Pythonic" to me. In existing control statements the condition goes before the colon, and the colon signals the start of a block. I think the first syntax seems the most intuitive, with the second syntax it might not be obvious how it's different from a normal "while" loop.

Is it possible to consider a different keyword, such as do/until or repeat/until instead of do/while to further distinguish it? (In the case of repeat/until, a 'repeat' without an 'until' could be a shorthand for 'while True'.)

I think your "should be compiled to" example was meant to be:

while True:
    ...
    if not (cond):
        break

Sitwon avatar Apr 15 '21 13:04 Sitwon

is this issue open for work?

rajpratyush avatar Jul 04 '21 11:07 rajpratyush

@rajpratyush No—I haven't decided on a good syntax for this yet.

evhub avatar Jul 04 '21 22:07 evhub

I don't know if this is really necessary. Coconut markets itself as a superset of python aimed for functional programming, where do-while doesn't fit that much. Anyhow, I'd vote for the this syntax, as it's much more readable:

do:
    ...
while: cond

FelipeSharkao avatar Sep 16 '21 12:09 FelipeSharkao