I’ve been examining some PHP code today and I’ve noticed the usage of do-while with breaks instead of if-else. What are the advantages of it? Code readability? Speed? Anything else?
Share
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.
do/while loops guaranteed that the body of the do/while is executed at least once, after which the loop condition is checked.
On the flip side,
ifguarantees that the code will not execute at all if the condition fails.Internally there’s no difference to them, except for the point at which the loop’s conditionals are checked.