如果没有在这里复制粘贴我的代码,如果它计算出“ X”的某个值,如何在运行时停止ADA程序执行代码行?
就像是:
variable_name := variable_name +4;
if variable_name >1 then
// END program here and dont execute any lines under this one
end if
Run Code Online (Sandbox Code Playgroud)
我不是编程新手,而是ADA新手,所以找到正确的语法很痛苦。有什么帮助吗?
没有任何特定的语法。
如果您处于主程序中,return则将很简单。
Ada83兼容的答案在SO上。
只要您没有任何任务,两者都可以。
有一个Ada95 Rosetta Code解决方案,无论您是否有任务都可以使用:
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;
Run Code Online (Sandbox Code Playgroud)
以及特定于GNAT的解决方案,也可以执行以下任务:
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;
Run Code Online (Sandbox Code Playgroud)