Ada:循环导致后面的代码无法访问

标签 ada

我是艾达的新手。我正在尝试使以下代码工作:

begin
Ada.Text_IO.Put_Line("Student ID Score");
Ada.Text_IO.Put_Line("===================");
readAnswers(pAnswers, 1);

loop
declare
   counter : Integer := 0;
   studentInput : String := Get_Line(Input);
   studentScore : Integer;
begin
   numOfTests := numOfTests + 1;
   current_student.ID := GetID(studentInput);
   Ada.Text_IO.Put(Ada.Strings.Unbounded.To_String(current_student.ID));
   readAnswers(studentInput (6 .. studentInput'Last) ,0);
   studentScore := scoreTest(current_student.student_answer, current_answer_key, number_of_questions);
      Ada.Integer_Text_IO.Put(studentScore);
      New_Line(1);
end;
end loop;

Ada.Text_IO.Put_Line("===================");
Ada.Text_IO.Put("Tests Graded = ");
Ada.Integer_Text_IO.Put(numOfTests);
end;

不幸的是,GNAT 告诉我循环之后的所有代码都无法访问。我怎样才能让这个程序执行循环和它之后的代码?

最佳答案

你忘记了退出条件:

loop
  exit when condition;
end loop;

关于Ada:循环导致后面的代码无法访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59232836/

相关文章:

exception - Ada 83 异常是否包括资源清理?

generics - Ada 通用程序

sockets - 如何关闭等待服务器套接字监听的任务?

ada - 如何在 Ada 中读取大文件?

string - 将无界字符串转换为整数 Ada

调用从 Ada 返回数组的 C 函数

c++ - 如何将退出代码从 Ada 进程返回到调用 Windows 进程?

linux - ADA & GTK => 函数 Get_Text

Ada等效于C/C++中的局部静态变量

ada - 包不可见错误