The switch statement has the following form:
switch(variable)
{
case value1: block; break
…
case valueN: block; break
default: block; break
}
The keyword switch argument variable is either a variable or function name. The variable or the function return must be either numeric scalar or string. Hence the arguments for the keywords case and default also must be of same types. The last default case is optional. Here is an example:
> a=1; switch(a) {
case 1: print(a); break
case 2: print(a); break
default: print(a); break
}
1