|
Not as a modifier |
Top Previous Next |
|
The $If statement can contain a Not modifier. If so the GAMS statementtoexecute will be compiled and executed only when the conditional is false. The basic form of the $If not command is
$If NOT conditional statementtoexecute $Ifi NOT conditional statementtoexecute Example: scalar x /1/; *$ondollar scalar y /1/; $Setglobal gg $Setglobal tt doit $If setglobal gg display x; $If not setglobal gg display y; $If "%tt%" == "doit" x=x*2; $Ifi "%tt%" == "DOIT" x=y**2; $If "%tt%" == "DOIT" x=x*100; $If not "%tt%" == "doit" y=y/4; $set aa yes $If "%aa%" == yes y=x;
The resultant effect on the compiled code is
1 scalar x /1/; 2 *$ondollar 3 scalar y /1/; 6 display x; 8 x=x*2; 9 x=y**2; 13 y=x;
Note lines in blue are suppressed because the $If fails while the magenta, orange, red and violet lines occur since the conditionals are true. The contrast between the lines
$Ifi "%tt%" == "DOIT" x=y**2; $If "%tt%" == "DOIT" x=x*100;
where the second line fails since tt was set to "doit". This shows the case sensitive nature of $If versus the case insensitivity of $Ifi. |