如何在我的程序中停止执行 [英] How to stop execution in my program

查看:174
本文介绍了如何在我的程序中停止执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果没有在这里复制粘贴我的代码,如果它计算出"X"的某个值,如何在运行时停止ADA程序执行代码行?

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'?

类似:

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

我不是编程新手,而是ADA新手,所以找到正确的语法很痛苦.有帮助吗?

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

推荐答案

对此没有任何特定的语法.

There isn’t any specific syntax for this.

如果您位于主过程中,则只需一个简单的return即可.

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

与Ada83兼容的答案是在SO上.

An Ada83-compatible answer is here on SO.

只要您没有任何任务,两种方法都可以.

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

有一个Ada95 Rosetta Code解决方案,无论您是否有任务,该解决方案都可以使用:

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;

和特定于GNAT的解决方案,也可以执行以下任务:

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;

这篇关于如何在我的程序中停止执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆