File:  [MW Coherent from dump] / coherent / a / usr / man / ALL / switch
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:34 2019 UTC (7 years ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent



switch                      C Keyword                      switch




Test a variable against a table


switch is a C keyword that  lets you perform a number of tests on
a variable in a convenient manner.  For example,


while(foo < 10)
        switch(foo) {
        case 1:
                dosomething();
                break;
        case 2:
                somethingelse();
                break;
        case 3:
                anotherthing();
                break;
        default:
                break;
        }
}


is equivalent to


while(foo < 10) {
        if(foo == 1) {
                dosomething();
                continue;
        } else if(foo == 2) {
                somethingelse();
                anotherthing();
                continue;
        } else if(foo == 3) {
         /* Note: compiler eliminates duplicate code */
                anotherthing();
                continue;
        } else
                break;
}


switch is always used  with the case statement, and nearly always
with the default statement.

***** See Also *****

break, C keywords, case, default, keyword, while






COHERENT Lexicon                                           Page 1



unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.