Programming-Idioms

History of Idiom 78 > diff from v4 to v5

Edit summary for version 5 :

Version 4

2015-09-01, 21:04:59

Version 5

2015-09-03, 11:41:50

Idiom #78 "do while" loop

Execute a block once, then execute it again as long as boolean condition c is true.

Idiom #78 "do while" loop

Execute a block once, then execute it again as long as boolean condition c is true.

Code
loop {
    doStuff();
    if !c { break; }
}
Comments bubble
Rust has no do-while loop with syntax sugar. Just use loop and break.
Demo URL
https://play.rust-lang.org/?code=fn%20main()%20%7B%0A%20%20%20%20let%20mut%20i%20%3D%205%3B%0A%09loop%20%7B%0A%09%09println!(%22%7B%7D%22%2C%20i)%3B%0A%0A%09%09if%20i%20%25%202%20%3D%3D%200%20%7B%20i%20%2F%3D%202%3B%20%7D%0A%09%09else%20%7B%20i%20%3D%203*i%20%2B%201%3B%20%7D%0A%09%09%0A%09%09if%20i%20%3D%3D%201%20%7B%20break%3B%20%7D%0A%20%20%20%20%7D%0A%20%20%20%20%0A%20%20%20%20println!(%22And%20final%20value%3A%20%7B%7D%22%2C%20i)%3B%0A%7D%0A&version=stable