SILK TEST FLOW OF CONTROL STATEMENTS
JAGAN MOHAN J
************************************************************************ Flow-of-control statements ************************************************************************ for each statement Action Iterates over the elements of a list or a set. Syntax for each item in expr statement Variable item expr statement
Description A variable name. An expression that evaluates to a list or a set. A single statement or a series of statements.
for statement numeric iteration Action Uses numeric iteration to control the number of times a statement executes. Syntax for loop-var = start-expr to end-expr [step step-expr] statement Variable loop-var
Description A loop variable to hold the current value of the for loop.
start-expr
A number which specifies the starting value of loopvariable.
end-expr
A number which specifies the end value of loopvariable.
step-expr
Optional for incrementing loop-variable by a value other than 1. Specify a positive number to increment, a negative number to decrement.Note You must specify an explicit step-expr to decrement a loop. For example, to decrement a loop by 1, specify step -1. If you fail to do this, the for statement skips the loop but does not generate an error.
statement
Code to be executed a specified number of times until loop-
var is outside the range start-expr to end-expr; either a single statement or a series of statements.
while statement Action Executes a statement zero or more times under control of a test condition. Syntax while boolean-expr statement Variable boolean-expr
Description A boolean expression that usually tests some state or relationship.
statement
A single statement, or a series of statements.
if statement Action Executes particular statements depending on the value of a condition. Syntax if boolean-expr statement [else statement] Variable boolean-expr
Description A boolean expression.
statement
A single statement, or a series of statements.
select statement Action Executes statements associated with a particular case from a group of cases. Syntax select case boolean-expr statements
[ case boolean-expr statements ]... [ default statements ] Variable statements
Description One or more statements.
boolean-expr
A boolean expression. If TRUE, control passes to the first statement in the clause.
switch statement Action Executes a particular statement depending on the value of an expression. Syntax switch (expr) case case-value(s) statement [case case-value(s) statement ]... [ default statement ]... Variable expr
Description An expression.
statements
One or more statements.
case-values
One or more expressions, separated with commas. If the value of expr equals one of the case-values, control passes to the first statement in the casevalues clause.
do ... except statement Action Handles (ignores) an exception without halting a script. Syntax do statements1
except statements2 Variable statements1
Description A single statement or series of statements that may generate an exception.
statements2
A single statement or series of statements (executed only if exception is raised in statements1).
raise statement Action Generates an exception and either transfers control to an exception handler or halts the script. Syntax raise [integer-expr [, expr [, cmd-line]]] Variable integer-expr
Description Optional. The number of the exception you want to raise in the Error Handler.
expr
Optional. An expression of any type that contains information about the exception. You can specify a string containing an explanation of the error, or you can get this information from SilkTest by calling the built-in 4Test function, ExceptData, inside the Error Handler.
cmd-line
Optional. An expression that contains a command line. If specified, the results file displays an icon on the error line. When you click the icon, the command line executes.
reraise statement Action Raises an exception again and passes control to the next exception handler. Syntax reraise Notes
Use reraise to raise an exception again, after an exception handler has trapped the original exception, but you want control to pass to the next exception handler, if any. reraise passes control to the next exception handler in the current block, or in any block in which the function that caused the exception is called. If no other exception handler is found, the script halts.
break statement Action Transfers control of the script out of the innermost nested for, for each, while, switch, or select statement. Syntax break Notes Use a break statement to terminate another statement early if specific conditions occur.
continue statement Action Begins the next iteration of a for, for each, or while statement without completing the current iteration. Syntax continue Notes The continue statement passes control back to the top of the loop it controls.
exit statement Action Exits from a script. Syntax Exit
goto statement Action
Bypasses the usual flow of control and passes control to the statement prefixed by a specified label. Syntax goto label Variable label
Description A label name, a valid 4Test identifier.
Notes 4Test interprets any valid identifier followed by a colon as a label. You can put a label anywhere in the code for a function.
return statement Action Returns control from a function to its calling function or from a child thread to its parent thread. Syntax return [expr] Variable expr
Description Optional. An expression whose value is returned to the calling function. The type of the value returned must match the declaration for the function.
Notes Use a return statement to return control from the function that currently has control to the function that called it. You can also use it to return a value to the calling function.
with statement Action Used to nest statements that reference the same window. An object reference that starts with a dot ( . ) is understood to refer to the window argument. Syntax with window .statement Variable window statement
Description A window. A single statement or a series of statements.
withoptions statement Note This feature is provided as a convenience to you, but it has not yet been thoroughly tested. Action Opens a block of code in which Agent options can be set for the duration of the block. Syntax withoptions statement statement
A single statement or a series of statements.
Notes User-defined functions cannot be called on block entry or exit. The previous values of the Agent options are restored on block exit, even if an error occurs. The error will be reraised after the options are restored.
use statement Action Causes a specified file or files to be included in the compilation of a testcase as though the contents of the file(s) were part of the testcase file. The use statement is functionally equivalent to a C include statement. It takes a string parameter which can be supplied in several ways, as shown below. Syntax use "FileName" or use sVar or use UseConstant Variable FileName
Description A file name or path name string. STRING.
sVar
A string constant that has been declared and set in a file that is included in this file prior to this use statement. STRING.
UseConstant
A compiler constant that you have defined and set with the SilkTest "Compiler Constants" window.
The compiler constant value must resolve to a string. Notes Window declarations and helper functions can be placed in a separate include file. This allows code that is used in many testcases to be placed in one file and then reused multiple times. A compiler constant allows you to customize a testcase before using it. For example, a testcase can be written that depends on the value of a constant that specifies the language to use. Before running the test you set the compiler constant to specify the language for this test run.
tag statement Action In a window declaration, defines one or more tags that the Agent uses internally to uniquely identify the object at runtime. The Agent generates tag statements for GUI objects when you record window declarations if you have turned off multiple tag recording (in Recorder Options). Note You never use the tag in your scripts to refer to an object; you always use the object's identifier. Syntax [ gui-specifier ] tag tag-string [ | tag-string ]… Variable gui-specifier
Description Optional. Specifies the GUIs that the statement applies to. See window declaration. If omitted, the statement applies to all GUIs.
tag-string
A STRING expression that evaluates to the object's tag. You can specify as many tag-strings as you want; separate them with the pipe character ( | ). The tag can be expressed in several ways.
spawn statement Action Begins execution of the specified statement in a new thread. Syntax spawn statement
Variable statement
Description Code to run in a new thread. statement can be a single statement or a series of statements.
setting statement Action The setting statement is used in the winclass declaration to define class-specific use of multiple tags and other features.
rendezvous statement Action Blocks execution of the calling thread until all threads that were spawned by the calling thread have completed. Syntax rendezvous Notes To create, or "spawn," multiple threads, use the statements parallel, spawn, rendezvous, and critical. When the last child thread exits, rendezvous unblocks the parent thread. If the calling thread has no child threads, rendezvous does nothing.
access statement Action Requests access to shared variables. Syntax access share-var [, share-var]... statements Variable share-var
Description The identifier of a shared variable. More than one shared variable can be requested by separating them with commas.
statement
One or more statements to be executed when access to all specified share-vars is granted.