comp.lang.ada
 help / color / mirror / Atom feed
From: Reinert Korsnes <reinert.korsnes@chello.no>
Subject: Re: Trivial Ada question
Date: Fri, 28 Jun 2002 12:54:50 +0200
Date: 2002-06-28T12:54:50+02:00	[thread overview]
Message-ID: <afhffb$pil$1@dolly.uninett.no> (raw)
In-Reply-To: mailman.1025258942.18931.comp.lang.ada@ada.eu.org

Yes, maybe the simplest possible.
The example below is also somehow simple,
but I hoped for some "exit name" solution
which I have not yet noticed :-)

reinert

 All_OK := 1;
 for I in A'Range loop
    if not some condition (I) then
       All_OK := 1;
       exit;
    end if;
 end loop;
 N := N + All_OK;


David C. Hoos, Sr. wrote:

> How about
> 
> All_OK : Boolean;
> .
> .
> .
> All_OK := True;
> for I in A'Range loop
>    if not some condition (I) then
>       All_OK := False;
>       exit;
>    end if;
> end loop;
> if ALL_OK then
>   N := N + 1;
> end if;
> 
> ----- Original Message -----
> From: "Reinert Korsnes" <reinert.korsnes@chello.no>
> Newsgroups: comp.lang.ada
> To: <comp.lang.ada@ada.eu.org>
> Sent: June 28, 2002 4:07 AM
> Subject: Trivial Ada question
> 
> 
>> Hi,
>> 
>> I would like to ask about a program construct:
>> 
>> I want to test if some condition holds for all values
>> of I in A'range and in this case the variable
>> N should be incremented by one ( N := N + 1; ).
>> How can I do this most elegant and effective with Ada95
>> (without "goto") ?
>> Assume I do not want to make a separate subroutine for this.
>> 
>> This example is simple but not computationally optimal (two tests):
>> 
>>     for I in A'range loop
>>         exit when "not some condition(I);
>>         if I = A'last then
>> -- Everything OK to the end:
>>            N := N + 1;
>>         end if;
>>     end loop;
>> 
>> This example is ugly but more computationally optimal (one test):
>> 
>>     for I in A'range loop
>>         if "not some condition(i)" then
>>            N := N - 1;
>>            exit;
>>         end if;
>>     end loop;
>>     N := N + 1;
>> 
>> Tricks by "named loops" also seem ugly.
>> 
>> reinert
>> 
>> _______________________________________________
>> comp.lang.ada mailing list
>> comp.lang.ada@ada.eu.org
>> http://ada.eu.org/mailman/listinfo/comp.lang.ada
>> 
>>




  reply	other threads:[~2002-06-28 10:54 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-28  9:07 Trivial Ada question Reinert Korsnes
2002-06-28 10:10 ` David C. Hoos, Sr.
2002-06-28 10:54   ` Reinert Korsnes [this message]
2002-06-28 10:57     ` Reinert Korsnes
2002-06-28 11:33       ` David C. Hoos, Sr.
2002-06-28 11:44     ` Ted Dennison
2002-06-28 21:38       ` Steven Deller
2002-06-28 12:29     ` Steve Sangwine
2002-07-03 18:59   ` Robert I. Eachus
2002-07-03 19:41     ` Darren New
2002-07-04  8:28       ` Lutz Donnerhacke
  -- strict thread matches above, loose matches on Subject: below --
2002-07-04  8:59 Grein, Christoph
2002-07-04  9:15 ` Lutz Donnerhacke
2002-07-05 22:25 ` Robert I. Eachus
replies disabled

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