comp.lang.ada
 help / color / mirror / Atom feed
From: "Steve Doiel" <nospam_steved@pacifier.com>
Subject: Re: Ada vs Delphi?
Date: 1999/08/15
Date: 1999-08-15T00:00:00+00:00	[thread overview]
Message-ID: <37b6db54.0@news.pacifier.com> (raw)
In-Reply-To: 37b54516.54588055@news.total.net


[snip]
>
> Getting back to my first example:
>
> <<<
>   for n1:= -128 to 127
>     for n2:= -128 to 127
>       begin
>         sum:= n1 + n2;
>         ...
>       end; {for}
> >>>
>
> how would you declare variables n1, n2, and sum in Ada?

In Ada you need not declare the loop variables.  If wish to you
can as I have done in the example below (a sample program which
does compile):

procedure ngdemo is

  type aByteRange is range -128..127;

  sum : Integer;

begin
  for n1 in aByteRange range -128 .. 127 loop
    for n2 in aByteRange range -128 .. 127 loop
      sum := Integer( n1 ) + Integer( n2 );
      -- If you try to compile using just
      --  sum := n1 + n2;
      -- you get a compile time error:
      --   expected type "Standard.integer"
      --   found type aByteRagne defined at line 3
    end loop;
  end loop;
end ngdemo;

In this example I have forced the indexes n1 and n2 to be
of a type that ranges from -128 to 127.  Clearly the intermediate
result for calculating sum would have to exceed this range, so
I cast both n1 and n2 to integer before performing the addition.

This is likely what is intended by the example.

But... I am making an assumption about casting the type of
n1 and n2 to Integer.  Ada does not make this assumption.  As
a matter of fact Ada makes no assumptions about how you wish
to operate or convert between types.  That is in my opinion one
of its advantages over Delphi.

SteveD






  parent reply	other threads:[~1999-08-15  0:00 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-08-06  0:00 Ada vs Delphi? Andre Ratel
1999-08-06  0:00 ` William Starner
1999-08-06  0:00   ` William Starner
1999-08-07  0:00   ` tmoran
1999-08-07  0:00     ` Aidan Skinner
1999-08-07  0:00       ` Gautier
1999-08-06  0:00 ` Steve Doiel
1999-08-09  0:00   ` Paul Groves
1999-08-08  0:00     ` Steve Doiel
1999-08-10  0:00       ` Ray Blaak
1999-08-10  0:00         ` Steve Doiel
1999-08-14  0:00           ` Andre Ratel
1999-08-09  0:00     ` Aidan Skinner
1999-08-09  0:00     ` Robert Dewar
1999-08-11  0:00       ` Andre Ratel
1999-08-11  0:00         ` Ted Dennison
1999-08-14  0:00           ` Andre Ratel
1999-08-16  0:00             ` Ted Dennison
1999-08-11  0:00         ` Robert Dewar
1999-08-14  0:00           ` Andre Ratel
1999-08-17  0:00             ` Robert I. Eachus
1999-08-11  0:00         ` Robert Dewar
1999-08-11  0:00           ` David Botton
1999-08-14  0:00           ` Andre Ratel
1999-08-09  0:00     ` Robert Dewar
1999-08-09  0:00     ` Gautier
1999-08-11  0:00       ` Andre Ratel
1999-08-12  0:00         ` Gautier
1999-08-12  0:00         ` Gautier
1999-08-14  0:00           ` Andre Ratel
1999-08-14  0:00             ` Gautier
1999-08-16  0:00               ` Gautier
1999-08-15  0:00             ` Steve Doiel [this message]
1999-08-17  0:00             ` Robert I. Eachus
1999-08-10  0:00     ` Brian Rogoff
1999-08-11  0:00       ` Scientific calculations (was Re: Ada vs Delphi? ) Vladimir Olensky
1999-08-11  0:00         ` Robert Dewar
1999-08-11  0:00         ` Robert Dewar
1999-08-11  0:00           ` Vladimir Olensky
1999-08-13  0:00             ` Gautier
1999-08-13  0:00             ` Robert Dewar
1999-08-13  0:00               ` Brian Rogoff
1999-08-15  0:00               ` Vladimir Olensky
1999-08-15  0:00                 ` Vladimir Olensky
1999-08-11  0:00     ` Ada vs Delphi? Andre Ratel
1999-08-11  0:00       ` Robert Dewar
1999-08-14  0:00         ` Andre Ratel
1999-08-11  0:00       ` Ada vs Component Pascal (was: Ada vs Delphi?) Ted Dennison
1999-08-07  0:00 ` Ada vs Delphi? Gautier
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox