if expressionstatementsendif expression1statementselseif expression2statementselsestatementsend
if conditionally executes statements. The simple form is
Theif expressionstatementsend
statements execute if the expression has all nonzero elements. The expression is usually the result of
expression rop expression
where rop is one of ==, <, >, <=, >=, or ~=.
More complicated forms use else or elseif. Each if must be paired with a matching end.
if, else, and elseif:
for i = 1:nfor j = 1:nif i == ja(i,j) = 2;elseif abs([i j]) == 1a(i,j) = 1;elsea(i,j) = 0;endendend
break,else,end,for,return,while
(c) Copyright 1994 by The MathWorks, Inc.