| MATLAB Function Reference | Search  Help Desk |
| elseif | See Also |
Conditionally execute statements
ifTheexpressionstatementselseifexpressionstatementsend
elseif command conditionally executes statements.
ifThe second block ofexpressionstatementselseifexpressionstatementsend
statements executes if the first expression has any zero elements and the second expression has all nonzero elements. The expression is usually the result of
expression rop expression
where rop is ==, <, >, <=, >=, or ~=.
else if, with a space between the else and the if, differs from elseif, with no space. The former introduces a new, nested, if, which must have a matching end. The latter is used in a linear sequence of conditional statements with only one terminating end.
The two segments
if A if A
x = a x = a
else elseif B
if B x = b
x = b elseif C
else x = c
if C else
x = c x = d
else end
x = d
end
end
end
produce identical results. Exactly one of the four assignments to x is executed, depending upon the values of the three logical expressions, A, B, and C.
break Terminate execution of for or while loop
else Conditionally execute statements
end Terminate for, while, and if statements and indicate
the last index
for Repeat statements a specific number of times
if Conditionally execute statements
return Return to the invoking function
switch Switch among several cases based on expression
while Repeat statements an indefinite number of times