Search code examples
sasscompass-sass

Does Sass have a switch function?


With Sass' ability to use variables, one would hope there is a large set of logic functions we can do with them.

Is there a way to do something like this?

$someVar: someValue !default;

@switch $someVar
{
    @case 'red':
        .arbitrary-css here {}

    @break;

    @case 'green':
        .arbitrary-css here {}

    @break;

    @case 'blue':
        .arbitrary-css here {}

    @break;
}

However, I can't find anything in the Sass reference about this.


Solution

  • Sass doesn't support Switch Case.

    Sass only support four control directives:

    • @if

    • @for

    • @each

    • @while