IDEC SmartAXIS FT9Z-1A01 User Manual page 328

Table of Contents

Advertisement

13: S
CR I P TS
Example 1.12 Conditional branch with switch using the default statement
Script
switch ([D0100])
{
case 0:
[D0102] = 0x1234;
break;
case 1:
[D0102] = 0x5678;
break;
default:
[D0102] = 0x9999;
break;
}
Operation Description
If the value of D0100 is 0, then 0x1234 is stored in D0102.
If the value of D0100 is 1, then 0x5678 is stored in D0102.
If the value of D0100 is not 0 nor 1, then 0x9999 is stored in D0102.
Example 1.13 Terminate the script with the return statement
Script
if (0x1234 == [D0100])
{
[D0102] = 0x5678;
return;
}
[D0103] = 0;
Operation Description
If the value of D0100 is not 0x1234, then 0 is stored in D0103.
If the value of D0100 is 0x1234, then 0x5678 is stored in D0102 and the script is terminated.
The return statement does not break out of a loop like the break statement, it terminates the script execution.
Example 1.14 Break out of a loop with the break statement
Script
[D0100] = 0;
[D0102] = 3;
[D0103] = 5;
while ([D0100] == 0)
{
[D0102] = [D0102] + 1;
if ([D0102] == [D0103)
{
SET([D0000.01]);
break;
}
}
Operation Description
While the value of D0100 is 0, the while statement is repeated until D0102 and D0103 match.
Inside the while statement, if the values of D0102 and D0103 are equal, the while statement will end and execution breaks out of
the while statement.
In the example above, the values of D0102 and D0103 match when the while statement is repeated twice, and after D0000.01
changes to 1, the while statement ends. After execution, the value of D0100 is 0, the value of D0102 is 5, the value of D0103 is 5,
and the value of D0000.01 is 1.
13-20
S
A XI S P
/ L
U
'
M AR T
R O
I TE
SER
S
M
FT9Y-B 1378
ANUAL

Advertisement

Table of Contents
loading

Table of Contents