Reputation:
How can I write an iterator in a procedure? Sorry for my dump question, I am novoice. Thanks for the answers.
Upvotes: 2
Views: 1464
Reputation: 13701
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;
Upvotes: 2
Reputation: 2344
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;
Upvotes: 0
Reputation: 103
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
Upvotes: 2
Reputation: 8522
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.
Upvotes: 5