Page 84 - Viva ICSE Computer Studies 8 : E-book
P. 84
Syntax:
switch(Expression)
Switch expression
{
Case 1:
..............................................
Case 1 Yes Statement 1
Task to perform
..............................................
No
break;
Case 2:
.............................................. Case 2 Yes Statement 2
Task to perform
.............................................. No
break;
Case 3: Case 3 Yes Statement N
..............................................
Task to perform
..............................................
break;
No Default statement End switch
default:
Default statement
............................................... Learn More
break; The default is the last statement of the Switch case.
}
Example: Write a program to accept a number from the user and print the corresponding day,
for example, 1 = Monday, 2 = Tuesday, 3 = Wednesday.
72