Logo Background

while

  • Written by matlabtutorialsmatlabtutorials No Comments Comments
    Last Updated: March 6, 2008

    Repeat statements an indefinite number of times.
    The general form of a statement is:

    expression
    statements
    END

    The statements are executed the real part of the expression
    has all non-zero elements. The expression is usually the result of
    expr rop expr where rop is ==, <, >, <=, >=, or ~=.

    The BREAK statement can be used to terminate the loop prematurely.

    For example (assuming A already defined):

    1
    2
    3
    4
    5
    6
    
    E = 0*A; F = E + eye(size(E)); N = 1;
    while norm(E+F-E,1) &gt; 0,
    E = E + F;
    F = A*F/N;
    N = N + 1;
    end

    See also for, if, switch, break, end.