|
$Ife conditionals |
Top Previous Next |
|
This tests a numerical expression at compile time using values in control variables.
The format is $Ife %controlvariable%op item command or $Ife %controlvariable% command where %controlvariable% is the name of the control variable to test op is = to test equality == to test equality with a tolerance > to test greater than < to test less than <> to test not equal item is the item to compare with which is either another control variable arising from an eval, valglobaol or evallocal a constant command is a statement to execute in the GAMS program if the condition is true Example: (setcontrol.gms) $set znumber 4 $Evalglobal anumber %znumber%+10 $Evalglobal xnumber %znumber%+9 $ife %anumber%>14 display "it exceeds 14", "%anumber%"; $ife %anumber% == %anumber2% Display "they are close" ; $ife %anumber%<14 display "it is less than 14", "%anumber%" $ife %anumber%=14 display "it equals 14", "%anumber%" $ife %anumber%<>14 display "it does not equal 14", "%anumber%" $ife %anumber%>%vnumber% display "it exceeds vnumber","%anumber%","%vnumber%" $ife %anumber% display "anumber is nonzero again"; Notes:
$ife %anumber% display "anumber is nonzero"; then it is same as $ife %anumber% <> 0 display "anumber is nonzero"; i.e. the program tests whether an item is nonzero.
|