Skip to main content

Posts

Showing posts with the label switch statements

Statements: switch, break, continue, goto in C programming

Switch Statement: This is a multi-directional conditional control statement. Sometimes, there is a need in program to make choice among number of alternatives. For making this choice, we use the switch statement. The general syntax is switch(expression) { case constant1: statements ; break ; - - - - - - - - case constantN: statements ; break, default: statements ; } Here, switch, case and default are keywords. The ‘expression’ following the switch keyword can be any C expression that yields an integer value or a character value. It can be value of any integer or character variable, or a function call returning on integer, or arithmetic, logical, relational, bitwise expression yielding integer value. The constants following the case keywords should be of integer or character type. These constants must be different from each other. The statements under case can be any valid C statements like if...else, while, for or even another switch statement. Writi...