logo for matrixlab-examples.com
leftimage for matrixlab-examples.com

Control Structures (while statement loop)

Among the control structures in programming languages, there is the while... end loop which repeats a group of statements an indefinite number of times under control of a logical condition.




Syntax:
while expression
    statements
    ...
end

Example:



counter = 100;

while (counter > 95)
   disp ('counter is still > 95')
   counter = counter -1;
end
disp('counter is no longer > 95')



Matlab response is:

counter is still > 95
counter is still > 95
counter is still > 95
counter is still > 95
counter is still > 95
counter is no longer > 95
>>


The cautions involving matrix comparisons that are discussed in the section on the if statement also apply to the while statement.


 From 'control structures' to home

 From 'control structures' to 'Matlab Control Flow'
 


Top

Switch Statement

For - Statement

If - Statement





footer for control structures (while-statement) page