Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
165 views
in Technique[技术] by (71.8m points)

ada - How to stop execution in my program

Without copy-pasting my code here, how can I stop my ADA program from executing anymore lines of code during run-time if it calculates a certain value to 'X'?

something like:

 variable_name := variable_name +4;
 if variable_name >1 then
 // END program here and dont execute any lines under this one
 end if

I am not new to programming but new to ADA so finding the correct syntax is a pain. Any help?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There isn’t any specific syntax for this.

If you are in the main procedure, a simple return will do.

An Ada83-compatible answer is here on SO.

Both those are OK so long as you don’t have any tasks.

There’s an Ada95 Rosetta Code solution, which will work whether you have tasks or not:

with Ada.Task_Identification;  use Ada.Task_Identification;

procedure Main is
   -- Create as many task objects as your program needs
begin
   -- whatever logic is required in your Main procedure
   if some_condition then
      Abort_Task (Current_Task);
   end if;
end Main;

and a GNAT-specific solution, also OK with tasks:

with Ada.Text_IO; use Ada.Text_IO;
with GNAT.OS_Lib;
procedure Stopping is
   procedure P is
   begin
      GNAT.OS_Lib.OS_Exit (0);
   end P;
begin
   Put_Line ("starting");
   P;
   Put_Line ("shouldn't have got here");
end Stopping;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...