5.4 While Loops

A while loop is a construction of the form

while condition, program, end

Here condition is a MATLAB functionm, as with the branching construction. The program program will execute successively as long as the vlaue of condition is not 0. Here is a sample program.

function l=twolog(n)

% l=twolog(n). l is the floor of
% the base 2 logarithm of n.

l=0;
m=2;
while m<=n
   l=l+1;
   m=2*m;
end


Next Section: 5.5 Recursion


Created by F.G. Garvan (fgarvan@ufl.edu) on Wed, Oct 01, 97
Last update made Thu Oct 2 11:22:23 EDT 1997.
Back to 5.3 For Loops
Back to Table of Contents
EMAIL: fgarvan@ufl.edu fgarvan@ufl.edu