if, elseif, else
Execute statements if condition is true
Syntax
ifexpression
statements
elseifexpression
statements
elsestatements
end
Description
if
evaluates an expression,
and executes a group of statements when the expression is true. An
expression is true when its result is nonempty and contains only nonzero
elements (logical or real numeric). Otherwise, the expression is false.expression
, statements
,
end
The elseif
and else
blocks
are optional. The statements execute only if previous expressions
in the if...end
block are false. An if
block
can include multiple elseif
blocks.
Examples
More About
Tips
You can nest any number of
if
statements. Eachif
statement requires anend
keyword.Avoid adding a space after
else
within theelseif
keyword (else if
). The space creates a nestedif
statement that requires its ownend
keyword.
Extended Capabilities
Version History
Introduced before R2006a