boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

020-switch.c (564B)


      1 /* tests/cc-e2e/20-switch.c — switch with case fall-through and default.
      2  * Split from 01-kitchen-sink. */
      3 
      4 int test_switch(void) {
      5     int r = 0;
      6     int i;
      7     for (i = 0; i < 4; i = i + 1) {
      8         switch (i) {
      9             case 0: r = r + 1; break;
     10             case 1: r = r + 2; break;
     11             case 2:
     12             case 3: r = r + 10; break;
     13             default: r = r + 100; break;
     14         }
     15     }
     16     return r;                       /* 1 + 2 + 10 + 10 = 23 */
     17 }
     18 
     19 int main(int argc, char **argv) {
     20     if (test_switch() != 23) return 1;
     21     return 0;
     22 }