Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do while loops #94

Open
dempo93 opened this issue May 1, 2020 · 1 comment
Open

Do while loops #94

dempo93 opened this issue May 1, 2020 · 1 comment

Comments

@dempo93
Copy link

dempo93 commented May 1, 2020

I think it is worth mentioning that do..while loops can be achieved by prepending the body of the loop to the condition

   let x=1;

   // while loop
   while {x == 0}{
        println!("This is not executed");
   } 

   // do while loop
   while {
        println!("This is executed");
        x == 0
   }{} 
@ThirteenPeeps
Copy link

ThirteenPeeps commented May 29, 2020

while {
    println!("This is executed");
    x == 0
}{} 

Devil's advocate here -

This form might be misleading to beginners (such as myself) since it's not really a do-while, it's explicitly a while with an empty body and a rather complex condition. You can't break or continue in it, for example, and at first glance, the syntax kind of obscures what's actually going on.

So I would understand leaving this out so as to not encourage that kind of hack—or perhaps include it, but in the context of "This is technically possible but probably not good form."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants