There is no 1-to-1 correspondence to the C++ do while loop in MATLAB. Your best option is to use a while loop. The difference is that whileloops check the condition at the beginning of the loop while do while loops check the condition at the end of the loop.
while (abs(A-B) <= 50)
...
end
To check the condition at the end of the loop using a whileloop, use an if statement inside the while loop:
The problem here is that you have to calculate twice. our calculation have to be done once before the loop and again inside the loop. that leads to repetition of a part of a code. what should we do in such a case?
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
2 Comments
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/115403-do-while-loop-in-matlab#comment_195347
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/115403-do-while-loop-in-matlab#comment_195347
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/115403-do-while-loop-in-matlab#comment_643136
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/115403-do-while-loop-in-matlab#comment_643136
Sign in to comment.