% while synatx: while expression, statements, end % calculating eps eps = 1; while (1+eps) > 1 eps = eps/2; end eps = eps*2 % example of non-evaluation of expression A = 0; B = 1; while (A && B), B, end % example where the expression is evaluated fully A = 1; B = 2; while (A || B), B, end % multiple expressions while (b ~= 0) && (a/b > 18.5) if exist('myfun.m') && (myfun(x) >= y) if iscell(A) && all(cellfun('isreal', A)) % Empty Arrays % In most cases, using while on an empty array returns false. % There are some conditions however under which while evaluates % as true on an empty array. Two examples of this are A = []; while all(A), do_something, end while 1|A, do_something, end %========================================================================== % break syntax: break % break is not defined outside a for or while loop. % example: fid = fopen('fft.m','r'); s = ''; while ~feof(fid) line = fgetl(fid); if isempty(line), break, end s = strvcat(s,line); end disp(s) %========================================================================== % continue syntax: continue % continue passes control to the next iteration of the for or while loop %in which it appears, skipping any remaining statements in the body of the loop. % example: fid = fopen('magic.m','r'); count = 0; while ~feof(fid) line = fgetl(fid); if isempty(line) | strncmp(line,'%',1) continue end count = count + 1; end disp(sprintf('%d lines',count));