And

Top  Previous  Next

When one wishes to perform an action if two or more conditionals are true simultaneously one can join them with an and operator.  This involves using syntax like

 

Action$(logical condition 1 and logical condition 2 and

                        Logical condition 3)

or

If((logical condition 1 and logical condition 2 and

                        Logical condition 3), Action);

or

While((logical condition 1 and logical condition 2 and

                        Logical condition 3), Action);

Examples:

(complexcond.gms)

u(k)$(s(k) and t(k)) = a(k);

u(k)$(s(k) and u(k) and t(k)) = a(k);

loop(k,if(s(k) lt 0 and t(k), u(k) = a(k)) );

Notes:

All of the logical conditions must be simultaneously true for the total logical condition to be true.
The and operator can be mixed with other and, or, not, xor, nested $ in a complex logical condition.  When this is done GAMS will execute the various statement components according to a predefined operator precedence.  However it is advisable to be cautious and use parentheses to carefully control the meaning of the condition.