# elseif

## Purpose

Conditionally execute statements.

## Synopsis

    if expression
        statements
    elseif expression
        statements
    end

## Description

`elseif` conditionally executes statements.

    if expression
        statements
    elseif expression
        statements
    end

The second block of `statements` executes if the first `expression` has any zero elements and the second `expression` has all nonzero elements. The expression is usually the result of

    expression rop expression

where `rop` is `==`,`<`,`` `>`,`` `<=`,`` `>=`,`` or`` `~=`.

`else` `if`, with a space between the `else` and the `if`, differs from `elseif`, with no space. The former introduces a new, nested, `if`, which must have a matching end. The latter is used in a linear sequence of conditional statements with only one terminating `end`.

The following two segments produce identical results. Exactly one of the four assignments to `x` is executed, depending upon the values of the three logical expressions, `A`, `B`, and `C`.

    if A                         if A
        x = a                        x = a
    else                         elseif B
        if B                         x = b
            x = b                elseif C
        else                         x = c
            if C                 else
                x = c                x = d
            else                 end
                x = d
            end
        end
    end

## See Also

    break, else, end, for, if, return, while

(c) Copyright 1994 by The MathWorks, Inc.