MATLAB Function Reference Previous page   Next Page
case

Execute block of code if condition is true

Syntax

Description

case is part of the switch statement syntax which allows for conditional execution. A particular case consists of the case statement itself followed by a case expression and one or more statements.

The general form of the switch statement is

case case_expr compares the value of the expression switch_expr declared in the preceding switch statement with one or more values in case_expr, and executes the block of code that follows if any of the comparisons yield a true result.

You typically use multiple case statements in the evaluation of a single switch statement. The block of code associated with a particular case statement is executed only if its associated case expression (case_expr) is the first to match the switch expression (switch_expr).

Examples

To execute a certain block of code based on what the string, method, is set to,

See Also

switch, otherwise, end, if, else, elseif, while


Previous page  cart2sph cast Next page

© 1994-2005 The MathWorks, Inc.