SWITCH Statement in C Language:
(1) SWITCH Statement successively tests the value of an expression against a list of integer or character constants. When a match is found, the statements associated with that constant are executed.
(2) Sample C language code and its output, as shown:

#include <stdio.h> #include <conio.h> int main() { int x; x = 2; switch(x) { case 1: printf(“LOW”); break; case 2: printf(“Medium”); break; case 3: printf(“High”); break; } getch(); return 0; } |
(3) After that go to the “Build” menu and select the “Build” option for publishing the code as shown.

(4) After building the code, press the “Run” button, as shown.

(5) After pressing the “run” button, the output screen is opened, as shown.

SWITCH Statement Syntax:
switch(expression) { case x: // code block break; case y: // code block break; // code block } |