# switch

Evaluates an expression, and executes the statement(s) associated with the appropriate case for the value of the expression.

## Syntax

    switch (expression) {
       case labelA:
          statementA
          break;
       case labelB:
          statementB
          [break;]
       ...
       default:
          defaultStatement
          [break;]
    }

## Example

    switch (whichDog)
    {
    	case 'lab':if (getDogType(lab))
    		alert("You have a labrador!");
    		break;

    	case 'golden': if (getDogType(golden))
    		alert("You have a golden retriever!");
    		break;

    	case 'pug': if (getDogType(pug))
    		alert("You have a pug!");
    		break;

    	default:
    		alert("You have no dog!");

    }

## Remarks

Use a "switch" statement in place of multiple "else if" statements for cleaner code.

text_javascript aptana_docs