$If and $Ifi

Top  Previous  Next

The $If statement causes execution of a GAMS statement when a conditional is true.  The basic form of the $If and $Ifi command is

 

$If conditional statementtoexecute

$Ifi conditional statementtoexecute

 

or with the instruction on the next line

 

$If conditional

 statementtoexecute

or

$Ifi conditional

 statementtoexecute

 

The net effect is that the code that GAMS will execute will either contain or not contain statementtoexecute depending on the true false nature of the conditional.  In particular, when the conditional in the $If or $Ifi test is true, then the statementtoexecute will be entered into the source code to be executed.  If not, then the statements statementtoexecute will never be executed.

Notes:

The $If makes comparisons involving text in a case sensitive fashion.  The $Ifi is a case insensitive variant.
The conditional is evaluated at compile time, so does not involve GAMS calculated numbers.
An example is in basicif.gms.
Surrounding a control variable name with % signs substitutes the text for that control variable in that place as illustrated and discussed below.