MATLAB Function Reference
else

Conditionally execute statements

Syntax

• ```if ```expression
```    ```statements1
```else
```statements2
```end
```

Description

`else` is used to delineate an alternate block of statements. If `expression` evaluates as `false`, MATLAB executes the one or more commands denoted here as `statements2`.

A `true` expression has either a logical 1 (`true`) or nonzero value. For nonscalar expressions, (for example, "if (matrix A is less than matrix B)"),` true` means that every element of the resulting matrix has a `true` or nonzero value.

Expressions usually involve relational operations such as `(count < limit)` or `isreal(A)`. Simple expressions can be combined by logical operators (`&`,`|`,`~`) into compound expressions such as `(count < limit) & ((height - offset) >= 0)`.

See `if` for more information.

Examples

In this example, if both of the conditions are not satisfied, then the student fails the course.

• ```if ((attendance >= 0.90) & (grade_average >= 60))
pass = 1;
else
fail = 1;
end;
```

`if`, `elseif`, `end`, `for`, `while`, `switch`, `break`, `return`, relational operators, logical operators (elementwise and short-circuit)