Promotic

switch - statement of language JavaScript

Description:
Executes one of several groups of statements, depending on the value of an expression.
Syntax:
switch (test_expression)
{
case value :
  statements
  break;


...


default:
  statements
  break;
}


test_expression - Number or text string.
statements - One or more statements executed if test_expression matches of value.
default - (optional) One or more statements executed if test_expression doesn't match any of the case clauses.
Note:
If value matches any case value, then the statements following after the case are executed up to the break.
If the statement break is not present, then the process continues to the following case sections - this way it is possible, for example, to merge multiple case sections - see Example1.
Default is used for processing unexpected values of value.

For similar purpose in the VBScript language is used the statement Select Case.
See also:
Example1:
One portion of statements may belong to multiple values (case 1: and case 2:):
Select and copy to clipboard

var sColor;
var nVar = 1;
switch (nVar)
{
case 1:
case 2:
sColor = "green";
break;
case 3:
sColor = "blue";
break;
default:
sColor = "black";
break;
}
Example2:
Statements can be written on a single row:
var nVar = 1, sColor;
switch (nVar)
{
case 1:
case 2: sColor = "green"; break;
case 3: sColor = "blue"; break;
default: sColor = "black"; break;
}
PROMOTIC 9.0.27 SCADA system documentation MICROSYS, spol. s r.o.

Send page remarkContact responsible person
© MICROSYS, spol. s r.o.