|
Numerical Value |
Top Previous Next |
|
One can test the numerical value of a control variable by using several syntax forms below
$Ife %controlvariablename% op valuetocompare statementtoexecute; $Ife %controlvariablename% statementtoexecute;
Notes:
= to test equality == to test equality with a tolerance > to test greater than < to test less than <> to test not equal
Examples: $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%>%xnumber% display "it exceeds xnumber","%anumber%","%xnumber%" $ife %anumber% display "anumber is nonzero again";
generates code that after compilation and looks like the following
39 *texttocompare 41 type1=ok; 42 type2=ok; 43 type3=ok; 44 type4=ok; 45 46 *add spaces 47 type1=ok;
This code shows that the quoted or uncontrolled quoted control variable name and target text works when spaces are not present. If spaces are present then the text retrieved by use of %controlvariablename% must be encased in quotes and if the comparison is to work so must be the target text.
Often one may wish to see if the text for an item is blank. This is frequently done with commands like the following
$If "%controlvariablename%a" == "a" display "blank it is"; $If not "%controlvariablename%a" == "a" display "it is not blank";
which contain the element "%controlvariablename%a" that reduces just to "a" if the named control variable does not have a text entry.
Examples employing the environmental variables appear in environvar.gms. |