Is
if(a)
{
do
{
b();
}
while(a);
}
exactly like
while(a)
{
b();
}
?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
They are the same and I will provide an example where you might actually want to use the “Do-While” instead of a while loop.
as opposed to
The argument for using a Do-While is shown above. Assume the line
x = superMathClass.performComplicatedCalculation(3.14);wasnt just one line of code and instead was 25 lines of code. If you need to change it, in the do while you would only change it once. In the while loop you would have to change it twice.
I do agree do whiles are off and you should avoid them, but there are arguments in their favor also.