The following table is a set of statements and keywords that can be used in the script.
Type | Description | |||||
| The | |||||
| The | |||||
| The | |||||
| A
| |||||
| 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
.
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 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.
Code Block | ||
---|---|---|
| ||
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 and increment , 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; } |
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
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 case
statements.
The CASE keyword case
statement must be followed by a constant value and terminated with a colon “ : ”. Tags, variables, or expressions cannot be used in a CASE case
statement. Only one DEFAULT default statement can be used in the SWITCH 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.
...