Switch Case Statement in C Programming with Example
Switch Case Statement in C Programming with Example What is a Switch Statement? A switch statement tests the value of a variable and compares it with multiple cases. Once the case match is found, a block of statements associated with that particular case is executed. Each case in a block of a switch has a different name/number which is referred to as an identifier. The value provided by the user is compared with all the cases inside the switch block until the match is found. If a case match is found, then the default statement is executed, and the control goes out of the switch block. In this tutorial, you will learn- What is a Switch Statement? Syntax Flow Chart Diagram of Switch Case Example Nested Switch Why do we need a Switch case? Rules for switch statement: Syntax A general syntax of how switch-case is implemented in a 'C' program is as follows: switch( expression ) { case value-1: Block-1; B