Switch Statement - C Statement

C examples for Statement:while

Introduction

The switch statement checks for equality between an integer and a series of case labels, and switch execution to the matching case.

It can end with a default label for handling all other cases.

Demo Code

#include <stdio.h>
int main(void) {
    int x = 0;/*from www  .ja  v a2 s  .co  m*/

    switch (x) {
      case 0: printf("x is 0"); break;
      case 1: printf("x is 1"); break;
      default: printf("x is not 0 or 1"); break;
    }
}

Result

The break keyword skips the rest of the switch cases.

If the break is missing, execution will fall through to the next case.


Related Tutorials