with Ada.Text_IO,Ada.Integer_Text_IO;
use Ada.Text_IO,Ada.Integer_Text_IO;
procedure LoopDemo is
Index,Count : Integer;
begin
Index:=1;
loop -- this is simlest loop
Put("Index=");
Put(Index,5);
New_Line;
Index:=Index+1;
exit when Index=5;
end loop;
Index:=1;
loop -- another simplest loop
Put("index=");
Put(Index,5);
New_Line;
Index:=Index+1;
if Index=5
then exit;
end if ;
end loop;
Count:=1;
while Count<5 loop -- this is the while loop
Put("Count=");
Put(Count,5);
New_Line;
Count:=Count+1;
end loop;
for Index in 1..4 loop -- this is the for loop
Put("Doubled index =");
Put(2*Index,5);
New_Line;
end loop;
for Count in reverse 5..8 loop -- this is the reverse for loop
Put("Triple index =");
Put(3*Count,5);
New_Line;
end loop;
for Index in 7..11 loop -- an empty loop
null;
end loop;
end LoopDemo;
014.Ada语言循环程序设计Demo01
最新推荐文章于 2025-08-16 09:13:29 发布
本文深入解析Ada编程语言中的循环结构,包括无限循环、while循环、for循环及其逆序版本,展示了如何通过不同的循环控制结构来实现重复执行的任务。文章通过具体代码示例,详细解释了各种循环的语法和使用场景。
622

被折叠的 条评论
为什么被折叠?



