WHILE - DO

Purpose

Allows repeated conditional execution of a command script.

Syntax

WHILE #const DO scriptfile { MAXTIMES # | NOLIMIT } {ECHO} @

Arguments and Subcommands

WHILE #const

A named constant used as a logical value for the IF condition. The condition is true if the value of #const is non-zero, and false otherwise. The script should modify the value of this constant.  Execution continues until the value of #cons is zero or the maximum number of iterations is reached. 

DO scriptfile

The name of the command script to be run if WHILE #const is not zero.  This subcommand must come immediately after the IF condition constant.

MAXTIMES #

Specifies the maximum number of times the loop is to be executed. The default value is 100.

NOLIMIT

Indicates that there is no limit on the number of times the code can be executed.  The code will be run repeatedly until the value of #const becomes 0.  The subcommand MAXTIMES -1  is equivalent to NOLIMIT.

ECHO

Echo all commands in scriptfile to the log file.  By default the commands in the script will not be echoed to the log window or written to the log file.  However output from commands like SHOW, SUM, MEAN , BOUND, or FIT will be written to the log window and in the log file.

Remarks

Note this command is intended for use with command scripts and should not be confused with the DOWHILE operation that can be used in transformations. The condition must be a single named constant; relational and logical expressions are not allowed. The break key (Ctrl on most systems) can be used to interrupt runaway loops. A WHILE loop is used in the LOOPTEST.PNT example.

Subcommands must be given after the DO scriptfile  subcommand.

Examples

a)  Run a simulation 50 times where SIMULATE.AMF contains a set of commands that generate some data, fit a model, write the results, and decrement the counter #runs.

CONS #runs = 50 @

WHILE #runs DO simulate.amf @

b)  Run a simulation 200 times where SIMULATE.AMF contains a set of commands that generate some data, fit a model, and write the results. The MAXTIMES counter is set to 200 so it is not necessary to decrement the counter in the simulation script. The #isok variable could be a dummy variable or it could be used to check for some other stopping criteria in the script.

CONS #isok = 1 @

WHILE #isok DO simulate.amf MAXTIMES 200 @