A for loop can be done in Ada using a range with a start and an end point:
for I in 0..10 loop
(...)
end loop;
I know, it's possible doing the for loop using two variables describing the range:
for I in range_start..range_end loop
(...)
end loop;
Is it also possible to store the range in one variable?, like:
for I in my_range loop
(...)
end loop;
Which type has the variable *my_range* to be?
Edit: Let's say I want to use this variable as a parameter in a subprogram: So the subprogram has this loop which iterates over the range. I'd rather use two variables describing the range instead of using generics, because generics would cause in higher effort. But I think using one variable describing the range would cause in a higher readability, that's why I'm asking that question.
A Variant is a special data type that can contain any kind of data except fixed-length String data. (Variant types now support user-defined types.) A Variant can also contain the special values Empty, Error, Nothing, and Null.
The variable “Rng” refers to the range of cells from A2 to B10. So, instead of writing “Range(“A2:B10″))” every time, we can write the word “Rng.”
In VBA we have a data type as a range that is used to define variables as a range that can hold a value of the range. These variables are very useful in complex programming and automation. Often variable range is used with the set statements and range method.
To use a range or a single cell as a variable, first, you need to declare that variable with the range data type. Once you do that you need to specify a range of a cell to that variable using the range object. This also gives you access to all the properties and methods that you can use with a range.
If your variable is an array, then you can iterate over its range via:
for I in Arr_Var'Range loop
...
end loop;
If you're interested in iterating over the elements of a container, e.g. array, vector, map, etc., and don't care about the index, you can use generalized looping (Ada 2012 only):
for Elem of Container loop
...
end loop;
Use a range
type, something along these lines:
type Range_Type is range -5 .. 10;
...
for A in Range_Type loop
See the complete example in here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With