Show/Hide Toolbars

CatchmentSIM Help

 

LOOP ( Loop Letter | Start At | End At | Loop Procedures)

 

The LOOP operator repeatedly processes a designated command sequence a set number of times.  On each loop of the command sequence any occurrences of the loop letter as a embedded parameter in the loop procedures are substituted with the current iteration of the loop.

 

Parameter

Description

Accepted Values / Data Type

Loop Letter

Designates the letter to substitute within the loop procedures with the current loop iteration.

Any single letter, traditionally i, j, k etc

Start At

Integer value for first iteration of loop.

Integer

End At

Integer value for final loop iteration.

Integer

Loop Procedures

Any number of embedded procedures or further logical operators designed for repetition within loop.

 

 

EXAMPLE

 

LOOP(i|1|%Catchment.NumberOfSubCatchments|
 TXT("Subbasin:")
 FTXT(L,10,1,0,%SubCatchment[i].Name);
)

 

This loop example will repeat three commands for every subcatchment within the current project.  These commands are:

Write the un-formatted text Subbasin:

Write the name of the subcatchment with ID value equal to the current iteration of the loop; and,

Start a new line (indicated by the semi-colon ';' command)

The right bracket on the bottom line is the partner of the left bracket of the LOOP operator and is necessary to designate the end of the loop procedures.

 

 

IF ( Test Variable | Test Type | Test Against | Success Procedures )

 

The IF operator will process or omit a designated command sequence based on application of a logical test.  The test compares two parameters, Test Variable and Test Against with reference to a Test Type as described in the following.

 

Parameter

Description

Accepted Values / Data Type

Test Variable

Designates the variable or value with which to compare with the Test Against value.

Any numeric or string value.

Test Type

Type of test to conduct.

=   : IF equal to

<    : IF lesser than

>    : IF greater

=< : IF lesser or equal to

>=  : IF greater or equal to

<>  : IF not equal to

Test Against

Variable or value to be tested against Test Variable using Test Type.

Any numeric or string value.

Success Procedures

Any number of embedded procedures or further logical operators designed for processing after application of a successful test.

 

 

EXAMPLE

 

LOOP(i|1|%Catchment.NumberOfSubCatchments|
IF(%SubCatchment[i].CatchmentOutlet|=|False|
   TXT("Downstream Subcatchment:")
   FTXT(L,25,1,0,%SubCatchment[i].DownstreamSubCatchmentName);
 )
)

 

This example loops through all the subcatchments in the current project and for each subcatchment the following IF test is initiated:

IF the Catchment Outlet project variable relating to the current subcatchment iteration in the loop is equal to (Test Type) the value False (Test Against) then the embedded IF procedures are processed, otherwise they are not processed.  

This sample code is designed to ensure that the downstream subcatchment name is only written for subcatchments that have a downstream subcatchment since the catchment outlet subcatchment will not have a downstream subcatchment.

 

 

WHILE ( Test Variable | Test Type | Test Against | Success Procedures )

 

The WHILE operator will process a designated command sequence continuously until a designated test is no longer successful.  The test parameters (Test Variable, Test Type and Test Against) are used identically to those described in the IF operator.   If the test fails on the first iteration, the Success Procedures will not be processed.

For a WHILE operator to be of use the Test Variable must be a user variable and must be re-assigned during the course of the Success Procedures.  Otherwise, the loop will either never process or process endlessly.

 

EXAMPLE

 

WHILE(&Continue_Processing|=|True|
{process commands}
   IF( {test for break while loop} |=|True|
      AssignVariable(&Continue_Processing,False)
   )
)

 

This example will continuously processes a set of commands (process commands) until a designated test is passed (test for break while loop) and will then assign a user variable (&Continue_Processing) a value of false, which will inturn cause the WHILE loop to terminate.