Articles added in Mathematics Lab | Cyber Lab is now open | Astronomy Lab is now open | VLSI Lab is now open | 120 SEO Tips article published | More exciting articles coming soon!




Switch-case statement

Switch is a conditional statement which will be used to select one set of statements from more than two alternative set of statements from more than two alternative sets of statements. Such a selection can be made using series of if-else statements also but that would make the understandability of program difficult.

Syntax:
switch(expression)
{ case value1: //statements
break;
case value2: //statements
break;
.
.
.
case valuen: //statements
break;

default: //statements
break;
}

--> switch, case, default, break are keywords.
--> Expression should not be of float or double type, but of int or char type.
--> value1,value2