Loop Statements-OCTAVE - Lab Class
Loop Statements-OCTAVE - Lab Class
disp(x);
% display the number
x = x +% 1;
increments x to ensure the loop
eventually terminates
end
% specifies where the loop's block of
statements stops, in this case x = 5
2. While Loop
disp(x);
% display the number
x = x +% 2;
increments x to ensure the loop
eventually terminates
end
% specifies where the loop's block of
statements stops, in this case x = 10
3. Do-Until Loop
The do-until loop executes the loop body first and
checks the condition at the end of each iteration.
This guarantees the loop executes at least once.
Syntax:
do
% code to be executed
until condition