Skip to end of metadata
Go to start of metadata

You are viewing an old version of this content. View the current version.

Compare with Current View Version History

« Previous Version 5 Next »

The following table is a set of statements and keywords that can be used in the script.

Type

Description

ifelse Statement

ifelse is a condition statements. It evaluates the expression after if. If the expression is true, then the code immediately following "if" will be executed. Otherwise, the contents immediately following "else" will be executed. The user can specify multiple cases to evaluate by using the else-if expression.

while/dowhile Statement

Statements for loop processes. while loop expression will continue to execute until the expression becomes false. As for the dowhile loop, do instruction code will always be executed at least once before while expression is evaluated. The loop will repeat until while expression becomes false.

for Statement

A for loop repeats until a specified condition becomes false.

switchcase Statement

Executing different processes based on different conditions.

continue Statement

Terminates execution of the current iteration in a loop and then execute the next iteration in a loop.

break Statement

Terminates the execution of a loop entirely.

return Function

Ends function execution and specifies a value to be returned to the function caller.

runScript() Function

runScript() is used to call another script program. For example, if runScript() is being used in script name "A" to call a script name "B", as soon as script A executes, script B will execute as well.

if...else

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 of another if...else statement using the else if statement. Please note that there is no limitation on how many else if can be nested inside of if...else.

For example:

if (A == 1) {

//run this instruction if A is equal to 1.

}

else if (A == 2) {

//run this instruction if A is equal to 2.

}

else {

//run this instruction if A does not equal 1 or 2.

}

 (2) WHILE/DO-WHILE Statement

The WHILE/DO-WHILE is a statement for a loop process. The statements below the WHILE keyword will be repeated as long as the condition followed by the WHILE keyword is True.

A = 0;

While (A<10)

{

// Write the program that will be repeated.  

// while the WHILE keyword’s condition is True.

// This example will be repeated 10 times.

A = A +1;

}

The subordinate statements will never be executed if the conditions for the WHILE statement are not true. If you use a DO-WHILE statement, the loop statement will be executed at least once. After the first execution, the system will check the condition within the WHILE statement.

Do {

// Write the loop statement when the condition is True.

// The loop statement will be executed once at least.

} While (A<10); // mark the end of the statement with ‘ ; ’.

(3) FOR Statement

In this statement, all expressions for the initialization, the decision-making, and the post-loop process are described in a single statement line.

The following example displays the WHILE statement example shown above but uses the FOR statement instead.

For (A=0; A<10; A=A+1)

{

// Write the loop statement.

}

The FOR statement is followed by the initialization statement, the decision-making statement, and the post-processing statement.

FOR (Initialization statement; Decision-Making statement; Post-Processing statement)

In the example above, the loop statement will be executed 10 times. On the first execution, A will have a value of 0. After this, the statement “A=A+1“ will execute, and the loop will run again. The loop will continue to run until A is equal to 10 or greater.

(4) SWITCH-CASE Statement

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 keyword 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.

  • No labels