本文概述
如果要检查的选项或条件不只一个, 请使用elseif关键字。
句法
if expression
Statements
elseif expression
Statements
else
Statements
end
if … elseif … else … end语句的流程图
例1
% program to compare two numbers
% generate random number for your age
n = randi(100, 1);
age = 23;
% check the number is greater than your age
if n > age
disp('i am younger')
elseif n < age
disp('you are younger')
else
disp('we are of same age')
end
输出
n = 9
you are younger
评论前必须登录!
注册