Question

How can I write an iterator in a procedure? Sorry for my dump question, I am novoice. Thanks for the answers.

Was it helpful?

Solution

It totally depends on what you need to iterate over.

An array? Use a loop: plain, for, or while.

One of the predefined containers? Use the iterator declarations associated with the container.

A string? Treat it like an array.

It would help if you provided more specifics about what you're trying to accomplish.

OTHER TIPS

See the Ada style guide

You can check the Ada 95 Rationale. There is an example there of an iterator which you might use as a starting point. Look here: http://www.adahome.com/LRM/95/Rationale/rat95html/rat95-p2-3.html#7

Since this question was asked, Ada 2012 came out, which now has proper support for user-defined iterators. You can now say:

for i of Some_Random_Object loop
  -- do stuff with i
end loop;

Details here and here.

Well, like others have said, it depends...

Personally, in my current project I find myself doing stuff like this quite a lot:

for Thing in 1..Number_Of_Things loop
 -- do stuff here
end loop;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top