with Ada.Text_IO,Ada.Integer_Text_IO;
use Ada.Text_IO,Ada.Integer_Text_IO;
procedure IfDemo is
begin
for Index in 1..7 loop -- this contain 2 simple if statements
Put("index is ");
Put(Index,3);
if Index <4 then
Put(" so is less than 4");
end if ;
if Index >5 then
Put(" so is more than 5");
end if ;
New_Line;
end loop;
New_Line;
for Index in 13..17 loop --this contain an else clause
Put("index is");
Put(Index,3);
if Index <15 then
Put_Line(" and is less than 15");
else
Put_Line(" and is 15 or greater.");
end if ;
end loop;
New_Line;
for Index in 13..17 loop -- this introduce the elseif statement
Put("index is:");
Put(Index,3);
if Index <15 then
Put_Line(" and is less than 15 ");
elsif Index=15 then
Put_Line(" and is 15");
elsif Index=16 then
Put_Line(" and is 16");
else
Put_Line(" and is greater than 16");
end if;
end loop;
New_Line;
-- this final group of statements contains a loop with a nested if
-- statements ,and a loop within the else part of the nested
-- if statement
for Index in 13..17 loop
Put("index is");
Put(Index,3);
if Index <16 then
if Index >14 then
Put(" and is less than 16 and greater than 14.");
else
Put(" and is less than or equal to 14");
end if ;
else
Put(" and is 16 or greater.");
for New_Index in 222 ..224 loop
Put(" stutter");
end loop;
end if ;
New_Line;
end loop;
end IfDemo;
016.Ada if语句
最新推荐文章于 2025-06-23 10:34:46 发布
本文深入探讨了Ada编程语言中的条件语句使用方法,包括简单的if语句、带else子句的if语句、elseif语句以及嵌套if语句的复杂应用。通过实例演示了如何根据不同条件执行不同的代码块。
1941

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



