Вы находитесь на странице: 1из 3

AVEVA PDMS/MARINE

Step-By-Step Tutorial
Author: Sergey Lebedev

DIFFERENT METHODS OF DO-LOOP WORKING

First get collection of some items to work with. In our example, it will be GLAB in Draft.

VAR !items COLLECT ALL GLAB FOR CE

1.Typical method with simple counter

do !x from 1 to !items.Size()
$P $!x : $!items[$!x]
enddo

Result:
1 : =16393/13458
2 : =16393/13459

Before colon - number of index (each next iteration of DO LOOP), after colon value of each next array
index (reference number in example)

2.A variant with storing values in a counter

do !x values !items
$P $!x
enddo

Result:
=16393/13458
=16393/13459

Counter !x will contain each next value from array index (reference number in example)

But if there is a need to get a number of index a new variable should be introduced like

!count = 1
do !x values !items
$P $!count : $!x
!count = !count + 1
Enddo

Result:
1 : =16393/13458
2 : =16393/13459


3.A variant with storing index numbers in a counter

do !x indices !items
$P $!x : $!items[$!x]
Enddo

Before colon - number of index (each next iteration of DO LOOP), after colon value of each next array
index (reference number in example)

AVEVA PDMS/MARINE
Step-By-Step Tutorial
Author: Sergey Lebedev

So this variant is equal to first one

4.Typical method with a simple counter and DO-LOOP step

do !x from 1 to !items.Size() by 2
$P $!x : $!items[$!x]
enddo

Result:
1 : =16393/13458
3 : =16393/13460
5 : =16393/13462

We can see that iterations start with 1 but next iteration is taken with step 2 skipping those which are
not in step

5. Typical method with a simple counter and DO-LOOP in specific point

do !x from 10 to !items.Size()
$P $!x : $!items[$!x]
Enddo

Result:
10 : =16393/13467
11 : =16393/13468
12 : =16393/13469

We can see that DO-LOOP started from 10
th
item skipping first nine items

6.Skipping values in DO-LOOP by condition

do !x from 1 to !items.Size()
SKIP IF (!x EQ 1 OR !x EQ 3)
$P $!x : $!items[$!x]
Enddo

Result:
2 : =16393/13459
4 : =16393/13461
5 : =16393/13462
We can see that array indexes with number 1 and 3 were skipped (not processed) as due to the SKIP
condition

7.Breaking DO-LOOP by condition

do !x from 1 to !items.Size()
BREAK IF (!x EQ 4)
$P $!x : $!items[$!x]
Enddo

Result:
1 : =16393/13458
2 : =16393/13459
AVEVA PDMS/MARINE
Step-By-Step Tutorial
Author: Sergey Lebedev
3 : =16393/13460

DO-LOOP breaks when counter become equal to 4 as due to the BREAK condition

NB.BREAK should be used in endless DO-LOOP when size of DO-LOOP is not known
do !x
BREAK IF (!x EQ 4)
$P $!x
Enddo

Result:
1
2
3
So if we had not put BREAK then this DO-LOOP would be endless and system would hanged

Вам также может понравиться