MATLAB Function Reference Previous page   Next Page
else

Conditionally execute statements

Syntax

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.

See Also

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


Previous page  ellipsoid elseif Next page

© 1994-2005 The MathWorks, Inc.