11.2) if...elseif...else...end Statement
- Flow control statements allow blocks of code to execute if particular conditions are met
- The simplest type is the "if" statement. If an expression is satisfied, then execute the statement. "if" statements are terminated with an "end". The syntax is as follows:
- "if" statements can container alternative choices specified by "else" and "elseif". The full syntax is as follows:
- If "logical_expression1" is satisfied, then execute "statement1". If it isn't satisfied, see if "logical_expression2" is satisfied. If it is then execute "statement2", "else" execute "statement2"
[matlab]
if (logical_expression)
statement
end
[/matlab]
[matlab]
if (logical_expression1)
statement1
elseif (logical_expression2)
statement2
else
statement3
end
[/matlab]