Programming and Data Types    

if, else, and elseif

if evaluates a logical expression and executes a group of statements based on the value of the expression. In its simplest form, its syntax is

If the logical expression is true (1), MATLAB executes all the statements between the if and end lines. It resumes execution at the line following the end statement. If the condition is false (0), MATLAB skips all the statements between the if and end lines, and resumes execution at the line following the end statement.

For example,

You can nest any number of if statements.

If the logical expression evaluates to a nonscalar value, all the elements of the argument must be nonzero. For example, assume X is a matrix. Then the statement

is equivalent to

The else and elseif statements further conditionalize the if statement:

if Statements and Empty Arrays

An if condition that reduces to an empty array represents a false condition. That is,

will execute statement S0 when A is an empty array.


  Flow Control switch