WhileLoop

(Engine-Level Function)

Description: Repeatedly executes its parameters while a condition is true.
Returns: Nothing
Usage: Script only.
Function Groups: Logic Control
Related to: Case | Cond | DoLoop | IfElse | IfThen
Format: WhileLoop(Condition, Function1, Function2, ...)
Parameters:  
Condition
Required. An expression that will be evaluated to determine if the Function parameters should be executed. If it is true, the Function parameters will be executed and then Condition will be re-evaluated and the process repeated until Condition is either false or invalid.
Function1, Function2, ...
Required. Are any expressions which are to be executed while Condition is true. The Function parameters are executed in order.
Comments: No other statement will execute as long as Condition is true. Care must be taken that the statement terminates since it has the potential of locking up the system if it does not exit.

While the WhileLoop statement has its place in VTScada programming, it should be noted that speed can be enhanced by a factor of approximately 5 through the use of array processing functions. Refer to ArrayOp1 and ArrayOp2 for further details.

Example:

  ...
  If 1 Main;
  [
    i = 1; 
    WhileLoop(i < 100 { Looping condition }, 
              arrayEven[i] = i * 2 { Store even numbers }; 
              arrayOdd[i] = i * 2 - 1 { Store odd numbers }; 
              i++); 
  ]

This causes all even numbers from 0 to 198 to be stored in arrayEven and all odd numbers from 0 to 198 to be stored in arrayOdd.