Existence/nonzero data item or result

Top  Previous  Next

One may wish to do conditional processing dependent upon whether the numerical value of a scalar item, set indexed parameter or calculation result is nonzero or not.  The form of the syntax that can be employed in such a case is

 

Action$Term

or

If(Term, statements);

or

While(Term, statements);

 

Examples from dataconditional.gms

 

Z=z+2$x;

If(x, z=2);

Eq5$doiwantconstraint..  zz=e=3;

Loop(I$(q(i)+q(i)**2),z=z+1)

While(x*x-1, z=z+2;x=x-1);

 

all of which will be executed if the item being tested in the conditional is nonzero.

This all could be expressed as $(Term <> 0) but this syntax is often utilized because it is more compact.