The script interpreter processes statements sequentially starting with the first statement of the program block. This sequential flow can be controlled with conditional statements that perform branching and iteration. Branching is controlled with an IF statement that directs execution along a given path. Iteration is controlled with loop statements that execute one or more statements repeatedly. Recursion is the process of a function calling itself either directly or indirectly through a second function.
Control statements are:
IF/THEN/ELSE, WHILE/BREAK/CONTINUE, RETURN
Part | Description |
---|---|
IF | The keyword to begin the control structure. |
Condition | A numeric or string expression that evaluates true (one) or false (zero). |
True-statements | Statement(s) performed when the condition is true. |
ELSE | (Optional) Keyword to begin the False control flow. |
False-statements | Statement(s) performed if the condition is false. |
If (userid != "") setField(userid,1,5);
If (userid != "") setField (userid,1,5)
else
errMsg("Userid must be specified");
If ( op == 5 )
{ setField(userid,1,5);
sendKey("Enter");
}
else
if (op == 3)
setField(pswd,2,5);
else
msgBox("unknown operation:);
if (prompt("enter Name") == "") errMsg("Name must be specified");
Part | Description |
---|---|
For | The keyword to begin the loop control structure. |
Initial-statement | A statement to be executed prior to the loop. |
Condition | A numeric or string expression that evaluates true (one) or false (zero). A function that returns an integer result. The loop continues to execute while this condition is true. |
Update-statement | A statement that will be executed at the end of each iteration. |
Loop-statements | Statement(s) performed when the condition is true. |
For ( i=0; i<3; i=I+1) waitforscreen(1000);
For ( i=0; i<3; i=i+1)
{
sendString(userid);
if (waitforstring ("Logon complete") > 0)
{
success = true;
break;;
}
}
A RETURN statement that is not within a function definition terminates the script.
Part | Description |
---|---|
RETURN | The keyword to pass control to the calling statements. |
return-value | An optional value to be returned to the caller. This can be a constant value, literal, or expression. |
.....
return 0;
Part | Description |
---|---|
While | The keyword to begin the control structure. |
Condition | A numeric or string expression that evaluates true (one) or false (zero). |
statements | Statement(s) performed while the condition true. |
cnt = 1;
WHILE (cnt < 3)
{
a = a+1;
cnt = cnt + 1;
}
// this will execute the loop 3 times
cnt= 1;
WHILE (cnt < 3)
{
userid = prompt("Enter Userid");
if (logon(userid) == 1) break;
cnt = cnt + 1;
}
cnt= 1;
WHILE (cnt < 3)
{
userid = prompt("Enter Userid");
if (logon(prompt("Enter Userid")) != 1)
{
msgBox("Invalid Logon id");
continue;
};
// do other logic....
}