Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

...

The following table is a set of statements and functions for the script.

Type

Description

ifelse Statement

The if statement executes the instruction code when the condition is true. Otherwise, the else statement will execute its instruction code. if...else statements can be nested inside another if...else statement using the else if statement which creates a nested loop. Please note, there is no limitation on how many else if can be nested inside if...else statement.

while Statement

The while statement execution will continue until the expression becomes false.

dowhile Statement

The do statement is executed at least once before while condition is evaluated. The loop will repeat until while condition becomes false.

for Statement

A for loop repeats until a specified condition becomes false. Below is the standard syntax used by a for loop:

Code Block
languagejs
for ([initialExpression]; [conditionExpression]; [incrementExpression]) {
    // instruction code
}

switchcase Statement

Only one default statement can be used in the switch statement. The switch expression is evaluated once by comparing the expression value with the values of each case. If matched, the associated instruction code is executed. Otherwise, default instruction code is executed.

Additionally, 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.

break Statement

Terminates a switch or a loop completely. The break statement prevents the execution of the following case in the switch statement. Adding a break function to the last case is good practice. If return is present, break statement is not necessary.

return Statement

Ends function execution and the function caller will return specifies a value.

default Statement

The default statement is optional and does not need a constant. break statement is not needed either. This statement will execute if no cases get executed.

continue Statement

The continue statement terminates execution of the current iteration in a loop and then execute the next iteration in a loop. This statement does not terminate the loop completely.

system.runScript() Function

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 runScript(), the caller will not wait until the end of the called program. Both the caller and called program will be executed in parallel.

Example for ifelse:

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
languagejs
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
languagejs
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
languagejs
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
languagejs
for (i = 1; i < 11; i = i + 1) {
    A = i;
}

Example for switchcase

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
languagejs
pet = "dog";
switch (pet) {
    case "cat":
        A = 1;
        break;
    case "dog":
        A = 2;
        break;
    case "hamster":
        A = 3;
        break;
}

Example forbreak

In this example, the string value “dog” is stored in a variable pet. Once the switch executes, an instruction code associated with case "dog": will execute and store value 2 to variable A. The return will then act as a break to prevent the next case to execute.

Code Block
languagejs
pet = "dog";
switch (pet) {
    case "cat":
        A = 1;
        break;
    case "dog":
        A = 2;
        break;
}

Example forreturn

In this example, the string value “cat” is stored in a variable pet. Once the switch executes, an instruction code associated with case "cat": will execute and store value 1 to variable A. The return will then act as a break to prevent the next case to execute.

Code Block
languagejs
pet = "cat";
switch (pet) {
    case "cat":
        A = 1;
        return;
    case "dog":
        A = 2;
        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 since there are no match cases.

Code Block
languagejs
pet = "bird";
switch (pet) {
    case "cat":
        A = 1;
        break;
    case "dog":
        A = 2;
        break;
    default:
        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
languagejs
A = 0;
while (A < 10) {
    A = A + 1;
    if (A === 5) {
        continue;
    }
}

Example forsystem.runScript()

In this example, when A equals 0, system.runScript() will run the script named “NewThread.”

...