Anonymous user
Loops/For with a specified step: Difference between revisions
→{{header|Ada|Provided working code and removed unnecessary comments.}}
(→{{header|Ada}}: Added incorrect template) |
|||
Line 2:
Demonstrate a for loop where the step value is greater than one.
=={{header|Ada}}==
The FOR loop construct in Ada does not give the programmer the ability to directly modify the loop control variable during the execution of the loop. Instead, we have to provide a range of even values to the loop, or multiply each value by two to get the same result.
<lang ada>with Loopers;
use Loopers;
end loop;▼
procedure For_Main is
begin
end loop;▼
package Loopers is
procedure Looper_1;
procedure Looper_2;
with Ada.Text_IO, Ada.Integer_Text_IO;
use Ada.Text_IO, Ada.Integer_Text_IO;
package body Loopers is
procedure Looper_1 is
Values : array(1..5) of Integer := (2,4,6,8,10);
begin
for I in Values'Range loop
Put(Values(I),0);
if I = Values'Last then
Put_Line(".");
else
Put(",");
end if;
end loop;
end Looper_1;
procedure Looper_2 is
E : Integer := 5;
begin
for I in 1..E loop
Put(I*2,0);
if I = E then
Put_Line(".");
else
Put(",");
end if;
end loop;
end Looper_2;
</lang>
=={{header|Aime}}==
|