user408141
user408141

Reputation:

Iterators in Ada

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

Answers (5)

David Given
David Given

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;

Details here and here.

Upvotes: 2

James Adam
James Adam

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

Nylus
Nylus

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

Marc C
Marc C

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

oluies
oluies

Reputation: 17831

See the Ada style guide

Upvotes: 3

Related Questions