Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms

Executable Statements Vol. 2
Divider

The Do-While and Do-Until statements

do-while-statement: [label] Do executable-statement While boolean-expression;

do-until-statement: [label] Do executable-statement Until boolean-expression;

The two Do loops execute the sub-statement once unconditionally. At the end of each iteration of the loop, the boolean expression is evaluated. The loop repeats:

Break causes execution to exit the loop unconditionally. Continue causes execution to jump to the bottom of the loop, where the boolean-expression is evaluated. Redo causes execution to jump to the top of the loop, without testing the boolean-expression.

The While and Until statements

while-statement: [label] While boolean-expression Do executable-statement

until-statement: [label] Until boolean-expression Do executable-statement

The While and Until statements repetitively execute the sub-statement as long as the boolean-expression:

Neither statement will execute even once if the test of the boolean-expression fails the first time.

The For statement

for-statement: [label] For (var-statement | init-xprimitive-statement) [boolean-expression]; inc-xprimitive-statement Do executable-statement
xprimitive-statement: function-call-statement | expression-statement

Note: the inc-xprimitive-statement ends with the Do keyword instead of a semicolon.

The For statement is the most powerful loop in QDL, and functions the same as the for in C/C++. It consists of three parts ("one", "two", and "three") separated by semicolons (;). Part one is intended for initialization, and is executed only once (before the first iteration of the loop, and before evaluating boolean-expression.) Part two is evaluated at the beginning of each iteration of the loop; if it is ommitted, the loop repeats unconditionally (i.e. is an infinite loop, except if exited by Break or Return.) Part three is executed at the end of each iteration of the loop, before testing the boolean-expression again.

Functionally, the For statement is equivalent to:

var-statement | init-expression-statement
While (boolean-expression) { executable-statement inc-xprimitive-statement }

Except that:

Example:

For X: Integer(0); X < 10; X++ Do {
	If X >= 3 && X <= 5 Then Continue;
	StdOut.Print X, '\t';
}
Output: 0	1	2	6	7	8	9

The Break, Continue, and Redo statements

break-statement: Break [label-identifier];

continue-statement: Continue [label-identifier];

redo-statement: Redo [label-identifier];

These statements can only be used inside loops (While, Until, Do-While, Do-Until, For) and Switch statements. In general:

Slightly more detailed explanation is found in the descriptions of each of the loop types.

The label-identifier specifies which loop or Switch the statement targets. It must match an identifier at the beginning of a loop or Switch in which the Break, Continue or Redo is enclosed. If no label-identifier is given, the Break, Continue or Redo statement applies to the innermost loop or Switch enclosing the statement. For example:

Label1: For X: Integer(0); ; X++ Do {       // Line 1
	If X == 1 Then Continue;                // Line 2
	Label2: While BooleanVariable Do {      // Line 3
		If X == 2 Then Break;           // Line 4
		If X == 10 Then Break Label1;   // Line 5
		AFunction;                      // Line 6
	}                                       // Line 7
}                                               // Line 8
// ...                                          // Line 9

(I don't have a purpose in mind for this code... it's just to illustrate.) The Continue on line 2 continues the For statement labelled Label1, and (theoretically, although a compiler is free to optimize provided that the result is functionally equivalent) jumps to line 8. The Break on line 4 applies to the innermost loop, Label2, so jumps past the end of the loop, to line 8. The Break on line 5, though, applies to the outer loop Label1, and jumps past the end of that loop, to line 9 or beyond.

The Try-Catch and Catch statements

try-statement: Try executable-statement catch-statement+
catch-statement: Catch (resolved-typeidentifier [, resolved-typeidentifier]* | identifier: resolved-typeidentifier) executable-statement

 

The Throw statement

throw-statement: Throw [throw-spec];
throw-spec: resolved-typeidentifier [initialize-spec];

A Throw statement with no operand re-throws the exception currently being handled. Such an expression should appear only in a Catch handler or in a function called from within a Catch handler. The re-thrown exception object is the original exception object (not a copy).

If the type of thrown exception is a class, which also has a base class (or classes), it can be caught by handlers that accept base classes of the exception’s type, or references to bases of the exception’s type. Note that when an exception is caught by a reference, it is bound to the actual thrown exception object; otherwise, it is a copy (like an argument to a function).

Table of Contents Qwertie's Site/Mirror
Next
Previous