Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What type has a variable containing a range to be?

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.

like image 300
clx Avatar asked Jan 21 '13 15:01

clx


People also ask

What is a Variant data type?

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.

What is the variable for range?

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.”

Can I use variable in range VBA?

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.

How do you use a variable in a range?

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.


2 Answers

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;
like image 86
Marc C Avatar answered Nov 07 '22 12:11

Marc C


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.

like image 41
Óscar López Avatar answered Nov 07 '22 11:11

Óscar López