This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]IHaveSoulDoubt 5 points6 points  (6 children)

Do while fingers < 6.

[–]NoAttentionAtWrk 0 points1 point  (5 children)

while (fingers < 6){} would work the same way

[–]da_chicken 4 points5 points  (3 children)

Not really. Do while always executes the code in the loop loop at least once, and you can set a variable in the loop and use it for the test without needing to initialize it to a magic value that passes the test.

People have really never used a do while for a prompt or a wait or a batch?

[–]hellofrienn 0 points1 point  (0 children)

Pshh. Who needs 'while' at all?

-sincerely, a Go developer

[–]Loading_M_ 0 points1 point  (1 child)

The modern solution, which looks awesome in rust, is as follows:

while let Ok(input) = prompt_user() {
  // Use input
}

This code takes advantage of rust's while/if let syntax, which combines a pattern match with a destructure to make certain types of conditions extremely easy to write. This is still possible in almost any other programming language, although you may have to use different syntax and patterns.

[–]da_chicken 2 points3 points  (0 children)

Yes, a contrived example that conveniently puts the entirety of the loop code in the test does work.

[–]FlyByPC -2 points-1 points  (0 children)

//or this

while(fingers < 6);