Mara Bos
Mara Bos

@m_ou_se

4 Tweets 4 reads Feb 06, 2023
"Why doesn't @rustlang have a do-while loop?" It actually does! It's just a bit hidden: while { body; condition } {}
Compared to the `do .. while (..);` of C and C++, Rust's version has the advantage that you can use variables of the body in the condition. ✨
Unfortunately, `break` and `continue` will not work as usual, when part of the condition.
However, using `break` and `continue` with a loop label still works:

Loading suggestions...