Doing statements and repeat while a condition is true (do)

do

Do statements and repeat while a condition is true


SYNTAX

do {
    statements
} while (condition)

The dowhile command executes the statements once and repeats the execution of those statements while the condition evaluates as true.

statements

A block of Sculptor code, enclosed within left and right braces.

condition

The condition to be tested. It may include all supported arithmetical, relational and logical operators. These are listed in the table of operators together with their order of precedence. Parentheses may be used to force a different order of evaluation.

If condition is an expression without a conditional test (e.g. 100; 34 + 6; “ABC”; tmp.FlagField), it is evaluated in the following way:

Numeric

An expression that evaluates to zero is false; one that evaluates to anything else is true.

Alphanumeric

An expression that produces a null string, or as tring containing only spaces, is false; all other alphanumeric expressions are true.

The condition is evaluated at the end of each iteration of the loop. If it is false, the loop terminates and control is passed to the statement following the condition.

Since condition is not evaluated until the end of each loop, the statements are always executed at least once. Note the difference between this and the while command, which tests condition at the beginning of the loop.

The special commands break and continue may only be used inside a loop.

The break command causes the loop to terminate and passes control to the statement following the condition.

The continue command causes the current iteration to end. Statements between the continue command and the right brace are skipped. Control passes to the test of condition to determine whether further loops are executed.


NOTES

  • The simple expression 1 may be used as a condition and causes a loop to repeat indefinitely. The only way to terminate such a loop is the break command. The pre-defined manifest constant TRUE could also be used.

  • The statements between the braces may contain other loop or switch constructs (for, switch, while or do).

  • Within a loop, a Sculptor command that uses trap clauses can use the special labels BREAK and CONTINUE. These have exactly the same effect as the break and continue commands.


EXAMPLE

!function CopyDir(SourcePath, DestPath) {
!temp CDExitCode,,i4
!temp CDHandle,,i4

     SculptorDir = getenv("SCULPTOR")
     KCopyDirPath = SculptorDir / "/bin/kcopydir.exe"
     ExecPath = KCopyDirPath / " " + SourcePath / " " +  DestPath
     CDHandle = execute(tmp.Server, tmp.ExecPath, NULL, 0, AA_HIDE)

     do {
          CDExitCode = exitcode(tmp.Server, CDHandle, 500)
     } while CDExitCode = CHILD_PROCESS_RUNNING

     if access(DestPath, TEST_EXISTS) = _FOUND then return OKAY else return ERROR
}

RELATED TOPICS

while

for

break

continue