The following table is a set of statements and keywords that can be used in the script.
Type | Description |
| The |
| The |
| The |
| A for ([initialExpression]; [conditionExpression]; [incrementExpression]) { // instruction code } |
| The |
| Terminates execution of the current iteration in a loop and then execute the next iteration in a loop. |
| Terminates the execution of a loop entirely. |
| Ends function execution and the function caller will return specifies a value. |
|
|
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
.
A = 1; if (A == 1) { A = 5; } else if (A == 2) { A = 10; } else { A = 0; }
Example for while
:
In this example, 0 is set as 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.
A = 0; while (A < 10) { A = A + 1; }
Example for do
...while
:
In this example, 0 is set as 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.
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.
for (i = 1; i < 11; i = i + 1) { A = i; }
Example for switch
…case
This statement is used when different processes are needed for different cases. Each case can be distinguished by an unlimited number of case
statements.
The case
statement must be followed by a constant value and terminated with a colon. Tags, variables, or expressions cannot be used in a case
statement. Only one default statement can be used in the switch
statement.
The DEFAULT statement does not need a constant. This statement is executed if none of the other cases are to be executed. The DEFAULT statement can be omitted if it is not needed.
The BREAK keyword plays the role of terminating the SWITCH statement. If there is no BREAK keyword after a CASE statement, then corresponding CASE/DEFAULT statements will also be executed. This means that multiple CASEs can execute the same result, as shown in the example below.
Switch (A) { Case 1: // Write the program when A is 1. Break; Case 5: Case 7: // Write the program when A is 5 or 7. Break; Default: // Write the default program. This section can be omitted. Break; } |
(5) CONTINUE Keyword
The CONTINUE keyword is used in loop statements. When the system meets the CONTINUE keyword, the flow skips the remainder of the loop and moves to the first part of the current loop. This keyword is often used in the WHILE, DO-WHILE, and FOR statements. It is especially useful when there are multiple decision-making statements (IF-ELSE) in the loop.
The following examples operate identically.
While (A<10) { A = A +1; If (A < 5) { // Process when A is less than 5 } Else { // Process when A is greater than or equal to 5 } } |
While (A<10) { A = A +1; If (A < 5) { // Process when A is less than 5 Continue; } // Process when A is greater than or equal to 5 } |
(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); |
(7) system.importScript Keyword
When you call an external program directly, the caller will be in standby mode until the called program (the external program) ends its operation.
If (A == 0) system.importScript(“ScriptName”); // Executes an external program ‘ScriptName’ A = A + 1; // Continues the rest of the program once external script has executed. |