The following table is a set of statements and functions for the script.
Type | Description | |||||
| The | |||||
| The | |||||
| The | |||||
| A
| |||||
| Only one default statement can be used in the Additionally, | |||||
| Terminates a | |||||
| Ends function execution and the function caller will return specifies a value. | |||||
| The | |||||
| The | |||||
| When an external program is called directly, the caller will be in standby mode until the called program (the external program) ends its operation. However, if an external program is called using |
Example for if
…else
:
In this example, if A
equals 1, assign 5 to A
. If A
equals 2, assign 10 to A
. If A
does not equal 1 or 2, assign 0 to A
.
Code Block | ||
---|---|---|
| ||
A = 1; if (A == 1) { A = 5; } else if (A == 2) { A = 10; } else { A = 0; } |
Example forwhile
:
In this example, 0 is the initial value for variable A
. When A
is less than 10, A
will increment by 1 every execution until A
equals 10. Once A
equals 10, the while
loop will end.
Code Block | ||
---|---|---|
| ||
A = 0; while (A < 10) { A = A + 1; } |
Example for do
...while
:
In this example, 0 is the initial value for variable A
. The do
statement will first be executed, incrementing A
by 1 every execution until equal to 10. Once A
equals 10, the do
...while
loop will end.
Code Block | ||
---|---|---|
| ||
A = 0; do { A = A + 1; } while (A < 10); |
Example for for
In this example, the initial expression is 1. When i
is less than 11, i
will increment by 1 and store the result in A
every execution until i
equals 11. Once i
equals 11, the for
loop will end.
Code Block | ||
---|---|---|
| ||
for (i = 1; i < 11; i = i + 1) { A = i; } |
Example for switch
…case
In this example, the “dog” string value is assigned to pet
. Once the switch
executes, an instruction code associated with case "dog":
will execute and assign 2 to variable A
. Then, the break
function terminates the switch
.
Code Block | ||
---|---|---|
| ||
pet = "dog"; switch (pet) { case "cat": A = 1; break; case "dog": A = 2; break; case "hamster": A = 3; break; } |
...
Example forreturn
In this example, the string value “dog” “cat” is stored in a variable pet
. Once the switch
executes, an instruction code associated with case "dogcat":
will execute and output Your dog is adorable!
store value 1 to variable A
. The return
will then act as a break to prevent next case to execute.
Code Block | ||
---|---|---|
| ||
pet = "dogcat"; switch (pet) { case "cat": returnA "Your cat is adorable!"= 1; case "dog": return; returncase "Your dog": is adorable!"; case "hamster": A = 2; return "Your hamster is adorable!"return; } |
Example for default
In this example, the “bird” string value is assigned to pet
. Once the switch
executes, an instruction code associated with default:
will execute and output Your bird is adorable!
since there are no match cases.
Code Block | ||
---|---|---|
| ||
pet = "bird"; switch (pet) { case "cat": A = 1; console.log(pet); break; case "dog": A = 2; console.log(pet); break; default: console.log("Your " + (pet) + " is adorable!") A = 3; } |
Example forcontinue
In this example, 0 is the initial value for variable A
. When A
is less than 10, A
will increment by 1 every execution. If A
equals 5, the continue
statement will terminate the execution of the current iteration, then execute the next iteration in a loop. Once A
equals 10, the while
loop will end.
Code Block | ||
---|---|---|
| ||
A = 0; while (A < 10) { A = A + 1; if (A === 5) { continue; } } |
(6) RETURN Keyword
Every program returns a result value to the caller. The RETURN keyword is used for designating a return value and termination of the program.
The following example processes three input parameters and returns the sum of them to the caller.
The name of the program shown below is MyPgm.
...
PARAM p1, p2, p3;
Return p1+p2+p3;
The program MyPgm will be called in another program as shown below. Then the variable ‘RtnValue’ will receive the value ‘6’.
...
RtnValue = MyPgm(1, 2, 3);
Example forExample forsystem.runScript()
In this example, when A
equals 0, system.runScript()
will run the script named “NewThread.”
Code Block | ||
---|---|---|
| ||
if (A == 0) { system.runScript("NewThread"); } |
If (A == 0)
system.importScript(“ScriptName”); // Executes an external program ‘ScriptName’
...