English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The decision structure requires the programmer to specify one or more conditions to be evaluated or tested by the program. If a condition is determined to be true, one or more statements to be executed should be specified. If the condition is true, other statements to be executed can be chosen. The condition is determined to be false.
The general form of the typical decision structure is common in most programming languages.-
MATLAB provides the following types of decision statements. Click on the following links to view their details.-
Serial Number | Statements and Descriptions |
---|---|
1 | if ... end statements An if...end statement consists of a boolean expression and one or more statements. |
2 | if...else...end statements An if statement can be followed by an optional else statement that 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 statements, and there is also an else statement, which is very useful for testing various conditions. |
4 | Nested if statements An if or elseif statement can be used within another if or elseif statement. |
5 | switch statement The switch statement allows testing whether a variable is equal to any value in a list of values. |
6 | Nested switch statements A switch statement can be used within another switch statement. |