I graduated in 1990 in Electrical Engineering and since then I have been in university, doing research in the field of DSP. To me programming is more a tool than a job.
Ada is based on old-style grammar, so basically we have the usual for loop (but only with +1 or -1 increments, a-la Pascal), while loop and just "loop" for never ending loops (you exit with an exit in the middle).
For loop allows for a very convenient construction. If V is an array you can write
for Idx in V'Range loop
V(Idx) := V(Idx)+1;
end loop;
to run over the index range of V. No risk of buffer overflow or off-by-one errors.
However, recently (Ada 2005 or 2012) the syntax of for has been extended in something that resembles the each loop in Ruby (compatibly with old syntax, of course). If Container is any kind of container (standard or defined by you) you can write
for Item of Container loop
Item := Item + 1; -- Here Item is an element stored in Container
end loop;
Very convenient. Not much different from the Ruby-sque
container.each do |item|
item = item+1;
end
The same syntax can be used even if Container is a simple array.
You also have an extension of "old school loop" for a container that is not an array
for Idx in Container.Iterate loop
Container(Idx) := Container(Idx)+1;
end loop;
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Ada is based on old-style grammar, so basically we have the usual
for
loop (but only with +1 or -1 increments, a-la Pascal),while
loop and just "loop
" for never ending loops (you exit with anexit
in the middle).For loop allows for a very convenient construction. If
V
is an array you can writeto run over the index range of
V
. No risk of buffer overflow or off-by-one errors.However, recently (Ada 2005 or 2012) the syntax of for has been extended in something that resembles the
each
loop in Ruby (compatibly with old syntax, of course). IfContainer
is any kind of container (standard or defined by you) you can writeVery convenient. Not much different from the Ruby-sque
The same syntax can be used even if Container is a simple array.
You also have an extension of "old school loop" for a container that is not an array