|
Existence |
Top Previous Next |
|
One can use a $If or $Ifi with or without the not modifier to test for whether or not the control variable has been set and if so execute a command otherwise skipping that command. The test to see if a control variable has been set is of one of three forms:
$If set controlvariablename statementtoexecute; $If setglobal controlvariablename statementtoexecute; $If setlocal controlvariablename statementtoexecute; $If setenv envronmentvariablename statementtoexecute;
The evaluation of each as to whether it is true or false depends on the characteristics of the set command used in its original definition. Several cases arise:
Example: $setlocal alocal yes $set aset yes $Setglobal aglobal yes acronyms local,global,plainset scalar type; *set item $If set aset type=plainset; $If setglobal aset type=global; $If setlocal aset type=local; *setglobal $If set aglobal type=plainset; $If setglobal aglobal type=global; $If setlocal aglobal type=local; *setlocal $Ifi set alocal type=plainset; $Ifi setglobal alocal type=global; $Ifi setlocal alocal type=local; *not set $If set qq type=plainset; $If setglobal qq type=global; $If setlocal qq type=local;
$If not set qq display "No qq around";
results in the echo print
17 *set item 18 type=plainset; 21 *setglobal 22 type=plainset; 23 type=global; 25 *setlocal 26 type=plainset; 28 type=local; 29 *not set 34 display "No qq around";
where line 18 shows that the command variable established with the $set the syntax passes only the $If set conditional while the setglobal command variable passes both the $If set and the $If setglobal conditionals. Also $setlocal command variable passes both the $Ifi set and the $Ifi setlocal condition. Finally, the referenced command variable qq that was never established within a set command did not pass any of the conditions except the last one with the not in it.
Examples employing the environmental variables appear in environvar.gms. |