Terminating a program: Abort

Top  Previous  Next

Conditionals may be used to cause the execution of the program to be terminated.  In such cases one employs a conditional in conjunction with the abort command.  The abort command operates just like a display command with the same syntax excepting the word abort replacing display but halts the program after it's execution.  The general format for a conditional abort command is

 

if(condition,abort listofitems);

or

abort$condition listofitems;

 

An example is given below (abort.gms)

 

scalar x /0/;

if(x > 0,abort "i stopped at first place",x;);

*note next command is redundant to above

abort$(x > 0) "i stopped with abort$ at first place",x;

display "i got past first place" ,x;

x=2;

abort$(x > 0) "i stopped with abort$ at second place",x;

*note will not get to next line

if(x > 0,abort "i stopped at second place",x;);

 

When encountered the abort command causes the job to stop with an execution error and displays the information in the command.

Abort can also be used unconditionally to stop a job just inserting the line

 

abort listofitems;

 

in the program.