SCAN

Top  Previous  Next

 

The SCAN statement scans the elements of a data collection.

 

 

Format

 

SCAN collection RESET

SCAN collection {FROM start} SETTING name {, value} {THEN statement(s)} {ELSE statement(s)}

 

where

 

collectionis a data collection variable.

 

startis the name of the collection element at which the scan is to begin.

 

nameis the variable that will be set to the name of the next element found by the scan.

 

valueis the variable that will be set to the value of the element.

 

 

The first form of the SCAN statement resets the scan position to be at the first element of the collection in collating sequence order.

 

The second form of the SCAN statement returns the next collection element. The optional FROM clause specifies the position of the first item to be returned. if there is no exact match, the scan position commences from where the start element would be in collating sequence order. Scanning a data collection does not descend into lower levels of nested collections.

 

At least one of the THEN and ELSE clauses must be present. The THEN clause will be executed if the scan is successful and name will be set to the name of the element. The optional value variable will be set to the value of that element. The ELSE clause will be executed if there are no further items to be extracted. The name and value variables will be returned as null strings.

 

 

Example

 

SCAN COL RESET

LOOP

  SCAN COL SETTING NAME, VALUE ELSE EXIT

  DISPLAY 'Element ' : NAME : ' has value ' : VALUE

REPEAT

 

This program fragment prints the name and value of each element of the data collection.

 

 

See also:

Data collections