for statements loop a specific number of times, and keep track of each iteration with an incrementing index variable. For example, preallocate a 10-element vector, and calculate five values: x = ones(1,10); for n = 2:6 x(n) = 2 * x(n - 1); end while statements loop as long as a condition remains true.
MATLAB Language Syntax ... Conditional Statements To determine which block of code to execute at run time, use if or switch conditional statements. Loop Control Statements To repeatedly execute a block of code, use for and while loops.
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 while loops check the condition at the beginning of the loop while do while loops check the condition at the end of the loop.