HyperMath

switch … case… default

switch … case… default

Previous topic Next topic No expanding text in this topic  

switch … case… default

Previous topic Next topic JavaScript is required for expanding text JavaScript is required for the print function  

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