For in Ada
On this page
Different Types of for
Loops in Ada
Ada’s looping constructs offer a versatile range of loop types similar in functionality. Here’s how you can achieve different types of looping constructs in Ada.
Basic Loop with a Single Condition
The most basic loop type uses a condition to control the repetition.
Classic Initial/Condition/Iteration Loop
This type of loop explicitly initializes the loop variable, checks the condition, and updates the variable after each iteration.
Iteration Using for
Loop Range
Ada’s for
loop can also iterate over a range with ease which is similar to iteration using range
.
Infinite Loop with break
Equivalent
A loop without a condition will repeat indefinitely until it encounters an exit statement to break out of the loop (equivalent to break
).
Using continue
Equivalent in a Loop
In Ada, the concept of continue
is achieved using exit when
followed by the condition you’d like to skip.
Running the Ada Program
To run an Ada program, you need to compile the .adb
file yielding an executable which can then be run.
Expected output for running the compiled program:
Gaining familiarity with these looping constructs will help in writing efficient Ada programs. In future examples, we’ll explore more detailed structures and functionalities in the language.