Reply to post: Re: Do...While

In Rust We Trust: Stob gets behind the latest language craze

Jimmy2Cows Silver badge

Re: Do...While

Depends where you want/need your loop termination check, which depends on what you're trying to do in the loop. Do you need to check before the loop iterates its content, or after?

Do you need:

to do something only if a clause permits it (while loop i.e. before), or...

to do something and then check the outcome (do-while loop i.e. after), ?

Do something only if it's permitted:

while( clause == true )

{

clause = DoSomething();

};

Do something and loop on the outcome:

do

{

clause = DoSomething();

}

while( clause == true )

Either form can usually satisfy both requirements with a little excess biolerplate, which makes it a matter of personal preference or enforced coding standards, and how much boilerplate you need to make it happen.

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon