Conditionally displaying information

Top  Previous  Next

Conditionals may be used to cause the display of information if certain conditions are met.  In such cases one usually employs a conditional in conjunction with the display command (Note the display command discussed in the Report Writing chapter).  One of two forms of the command generally appear.  The first involves the if syntax as discussed below where a display is executed if a particular condition is found to be true.  Second, one can have the word display followed by a $condition.  Therein the display will only occur if the $condition is true.

The general format for a these conditional display commands is

 

display$condition listofitems;

if(condition, display listofitems);

 

as illustrated just below (conddisp.gms)

 

scalar x /0/,y /10/;

display$(x+y le 0) "display when sum of x and y le 0",x,y;

x=2;

if(x gt 0,

    display "X and y here if x is positive",x,y;

  );

display$(x > -1) "display with display$ at second place",x;

if((x+y > 2),

    display "X and y at first place if x+y is greater than 2",x,y;

   );

if(x gt 0,display "X and y at first place if x is positive",x,y;);

 

All of these displays will only occur if the condition is true.