Conditions: Waiting for a condition

Updated: 2025-11-20

Imagine a group of people waiting for an automatic door to open. They are not queuing and they are not occupying anything; they are simply waiting for something to happen.

This is exactly what the CONDITIONS resource allows: stopping entities until a logical condition is met.

Something similar existed in classic GPSS with the ASSEMBLE block for this purpose. In GPSS-Plus, this behavior is replaced by a more general and flexible resource.

The CONDITIONS resource allows holding entities until a condition is satisfied. This condition is defined as an expression that is evaluated each time an entity attempts to pass.

CONDITIONS {NAME:Conditions1,X:208,Y:317,expression:(X$counter>=5)}

CONDITIONS has additional options that will be covered later.

Its associated block, WAITUNTIL, is responsible for validating the condition for the current entity — in this case, whether the counter is greater than or equal to 5.

When the 5th entity arrives, the condition is satisfied and it continues without being held. At that point, the remaining entities are released by checking all retained ones using another associated block: WAITCHECK.

It is interesting to observe that all entities leave the CONDITIONS resource together in the first segment. In the second one, the randomness of ADVANCE 20,40 causes them to spread apart.

We also begin using the ENDGENERATE block, which is more consistent with the structured approach than TERMINATE. They are equivalent, but syntactically it is more appropriate to structure the block using GENERATE/ENDGENERATE. This makes it easier to identify which block was generated, especially when multiple GENERATE blocks exist in the program.

Example

/* Synchronization: CONDITIONS / WAITUNTIL
Entities wait as a group and advance together.
*/

POSITION {NAME:POS1,X:208,Y:222}
POSITION {NAME:POS2,X:452,Y:215}
POSITION {NAME:POS3,X:752,Y:215}

CONDITIONS {NAME:Conditions1,X:208,Y:317,expression:(X$counter>=5)} ; Holding resource
INITIAL counter,0

START 100
;*****************************************************

GENERATE 10,2 {NAME:GEN1,X:86,Y:228,ERADIO:10,ECOLOR:#FF9900}

ADVANCE 16,0 {TO:POS1}
SAVEVALUE counter, X$counter + 1
WAITUNTIL Conditions1
WAITCHECK Conditions1
SAVEVALUE counter, 0
ADVANCE 20,0 {TO:POS2} ; ALL entities advance together to the second position
ADVANCE 20,40 {TO:POS3} ; Advance to the third position with random time between 20 and 40, now SPLITTING

ENDGENERATE 1 ; Ends the life of the entity — IDENTICAL to TERMINATE 1