![]() |
VOOZH | about |
You all are familiar with switch case in C, but did you know you can use a range of numbers instead of a single number or character in the case statement? Range in switch case can be useful when we want to run the same set of statements for a range of numbers so that we do not have to write cases separately for each value.
The syntax for using range case is:
case low ... high:
It can be used for a range of ASCII character codes like this:
case 'A' ... 'Z':
You need to Write spaces around the ellipses ( ... ). For example, write this:
// Correct - case 1 ... 5: // Wrong - case 1...5:
The below program illustrates the use of range in switch case.
1 in range 1 to 6 5 in range 1 to 6 15 not in range 20 in range 19 to 20