📅  最后修改于: 2020-11-03 09:46:38             🧑  作者: Mango
决策结构要求程序员应指定一个或多个要由程序评估或测试的条件,如果确定条件为真,则应指定要执行的一个或多个语句,如果条件为真,则可以选择要执行的其他语句。条件确定为假。
以下是大多数编程语言中常见的典型决策结构的一般形式-
MATLAB提供以下类型的决策声明。单击以下链接以查看其详细信息-
Sr.No. | Statement & Description |
---|---|
1 | if … end statement
An if … end statement consists of a boolean expression followed by one or more statements. |
2 | if…else…end statement
An if statement can be followed by an optional else statement, which executes when the boolean expression is false. |
3 | If… elseif…elseif…else…end statements
An if statement can be followed by one (or more) optional elseif… and an else statement, which is very useful to test various conditions. |
4 | nested if statements
You can use one if or elseif statement inside another if or elseif statement(s). |
5 | switch statement
A switch statement allows a variable to be tested for equality against a list of values. |
6 | nested switch statements
You can use one switch statement inside another switch statement(s). |