if expression
statements
end
if expression1
statements
elseif expression2
statements
else
statements
end
if
conditionally executes statements. The simple form is
Theif expression
statements
end
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:n
for j = 1:n
if i == j
a(i,j) = 2;
elseif abs([i j]) == 1
a(i,j) = 1;
else
a(i,j) = 0;
end
end
end
break
,else
,end
,for
,return
,while
(c) Copyright 1994 by The MathWorks, Inc.