4.13 XPOZ Script Flow Constructs

Declarations instantiate variables for use within a script. They consist of a data type, a variable name, and an optional assignment operator and variable value. Examples include:

int iterator = 0;
int iteratorA = 0;
char middleInitial = 'b';
string companyName = “Acme, Inc.”;

White space between operators and other tokens (for example, variable names, and values) is optional, but suggested for script readability.

A statement is either a single expression, or a block of statements. A single expression generally follows the C-language constructs, and allows the following operators:

Table 4-2 XPOZ Single Expression

C-Language Construct

Operators

assignment

=, +=, -=, *=, /=

logical AND

&&

exclusive OR

^

equality

==, !=

additive

+, -

unary (pre/post)

++,--

not

!

logical OR

||

bitwise OR

|

bitwise AND

&

relational

<, <=, >, >=

multiplicative

*, /

unary (post)

++, --

A block of statements encapsulates a set of statements with curly braces ({, }). Most often a block of statements is used in branch and loop constructs.

4.13.1 Branch and Loop Constructs

Branch Constructs

XPOZ allows two branch constructs: if-then-else and switch-case. The switch-case construct uses the break command to exit once it executes a desired branch.

If-Then-Else Statement Format

The else portion is optional:

  if (boolean statement) {
    statement block
  }
  [else {
    statement block
  }]
Switch-Case Statement Format
  switch(integer variable) {
    case <integer value>: statement block; [break;]
    ...
    case <integer value>: statement block; [break;]
    default: statement block [break;]
  }

Loop Constructs

XPOZ allows the following loop constructs: for, do-while, and while. The continue and break commands are allowed within loop constructs. The continue command ends the current iteration of the loop and proceeds with the following iteration. The break command ends the loop construct completely and continues with the next statement.

For Statement Format
  for([variable initialization]; boolean statement; [variable modification,]) {
    statement block
  }
Do-While Statement Format
  do {
    statement block
  } while(boolean statement);
While Statement Format
  while( boolean statement) {
    statement block
  }

A complete description of the XPOZ grammar (in BNF format) is included in Section A.0, XPOZ Grammar.

Return and Exit Commands

The return and exit commands can be used anywhere in a script. The return command ends the current script and returns to the calling script. The exit command ends the entire test.

Sample Script

The following is a short XPOZ script sample showing how an XPOZ script is called from another XPOZ script. Also, variable scope is shown.

FILE_1.xpoz
// *********************
// Declaring local variables
// *********************
string str1 = “This is FILE_1 string one”;
int inc;
for(inc=0; inc<5; inc++) {
  PrintToScreen(String = inc + “\n”);
}
PrintToScreen(String = str1 + “\n”);
PrintToScreen(String = str2 + “\n”);
//END OF FILE_1

FILE_2.xpoz
// *********************
// Declaring local variables
// *********************
string str1 = “This is FILE_2 string one - longer”;
string str2 = “This is FILE_2 string two”;
string str3 = “This is FILE_2 string three”;
string str4 = “This is FILE_2 string four”;
string str5 = “This is FILE_2 string five”;

length = Length( String = str1);
PrintToScreen( String = "[" + length + "]  " + str1 + "\n");

//Calling FILE_1.xpoz from FILE_2.xpoz
SubFile(FILE = "FILE_1.xpoz");
//END OF FILE_2

The output of executing FILE_2.xpoz is:

[34]  This is FILE_2 string one – longer
0
1
2
3
4
This is FILE_1 string one
This is FILE_2 string two