Difference between revisions of "UM:NetXMS Scripting Language (NXSL)"

→‎switch: example added
(→‎switch: example added)
Line 444: Line 444:


== switch ==
== switch ==
The ''switch'' statement is similar to a series of ''if'' statements on the same expression. In many occasions, you may want to compare the same variable (or expression) with many different values, and execute a different piece of code depending on which value it equals to. This is exactly what the ''switch'' statement is for.  
The ''switch'' statement is similar to a series of ''if'' statements on the same expression. In many occasions, you may want to compare the same variable (or expression) with many different values, and execute a different piece of code depending on which value it equals to. This is exactly what the ''switch'' statement is for.


Example:
  <nowiki>
  switch (input)
  {
    case "1":
      trace(0,"Input is 1");
      break;
    case "2":
      trace(0,"Input is 2");
      break;
    default:
      trace(0, "Input is unknown");
  }
  </nowiki>


== return ==
== return ==
57

edits