The comments section of the program |
/* Example on switch statement |
Start of the program |
#include <iostream.h> |
The variable of the switch statement is declared and it is assigned a value. This variable can be only of type integer or character. |
int section; |
The switch statement |
switch(section) |
The first block. If section has the value of the cases listed, the statements before the break will be executed. All other statements up to the closing bracket of the switch statement are bypassed. |
case 10: |
The second block. If section has the value of the cases listed, the statements before the break will be executed. All other statements up to the closing bracket of the switch statement are bypassed. |
case 12: |
The third block. If section has the value of the cases listed, the statements before the break will be executed. All other statements up to the closing bracket of the switch statement are bypassed. |
case 14: |
The fourth block. If section has the value of the cases listed, the statements before the break will be executed. All other statements up to the closing bracket of the switch statement are bypassed. | case 17: |
If the value of the switch variable is not listed in the earlier four blocks, then the default block is activated |
default: |
This part is common to any of the above five paths. |
cout<<" \n\n Have a nice day \n\n"; |
© 2001 J.Y. Kazakia. All rights reserved