comp.lang.ada
 help / color / mirror / Atom feed
From: Ada novice <ycalleecharan@gmx.com>
Subject: loop problem with exit condition
Date: Sun, 26 Sep 2010 01:14:10 -0700 (PDT)
Date: 2010-09-26T01:14:10-07:00	[thread overview]
Message-ID: <3087f399-2cae-4bc8-bba1-e728943473bb@e14g2000yqe.googlegroups.com> (raw)

Hi,
    I'm putting a simple code below with two loops. The Outer loop
ranges from -44.88 to 67.32 and should be subdivided equally in 300
points. The Inner loop ranges from 0.001 to 0.35 and should also be
subdivided in 300 points. I would like the limits of the range to be
included i.e. Outer loop has as first value -44.88 and last value as
67.32 . Inner loop has as first value 0.001 and last value as 0.35 .
Here's my code:

with Ada.Text_IO;
with Ada.Long_Float_Text_IO;
with Ada.Integer_Text_IO;



procedure Try is

   Count : Integer;
   Outer : Long_Float;
   Outer_Start : constant := -44.88;
   Outer_Limit : constant := 67.32;
   Outer_Step : constant := (Outer_Limit - Outer_Start)/299.0;

   Inner : Long_Float;
   Inner_Start : constant := 0.001;
   Inner_Limit : constant := 0.35;
   Inner_Step : constant := (Inner_Limit - Inner_Start)/99.0;


begin

   Count := 0;
   Outer := Outer_Start;


   loop
        Inner := Inner_Start;

        loop
          Count := Count + 1;

          exit when Inner > Inner_Limit - Inner_Step;

          Inner := Inner + Inner_Step;

   end loop;

      exit when Outer > Outer_Limit - Outer_Step;

      Outer := Outer + Outer_Step;


end loop;


      Ada.Text_IO.New_Line(2);
      Ada.Text_IO.Put("Inner after loop is (should be 0.35) ");
      Ada.Long_Float_Text_IO.Put (Item => Inner, Fore => 3, Aft  => 3,
Exp  => 0);
      Ada.Text_IO.New_Line(2);
      Ada.Text_IO.Put("Count after loop is ");
      Ada.Integer_Text_IO.Put (Item => Count);



end Try;


I am not able to get this working fine. The total time that both loops
should be entered must be 300 * 100 = 30k. I'm getting only Count as
29,700 and inner to be 0.346  (I understand that this is cause by my
exit condition).

How to create loops that follow my specifications?


Thanks a lot..







             reply	other threads:[~2010-09-26  8:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-26  8:14 Ada novice [this message]
2010-09-26  8:16 ` loop problem with exit condition Ada novice
2010-09-26  9:10   ` Dmitry A. Kazakov
2010-09-26 10:19     ` Ada novice
2010-10-26  2:59     ` Yannick Duchêne (Hibou57)
2010-10-26  7:02       ` Niklas Holsti
2010-10-26  8:24         ` Dmitry A. Kazakov
2010-10-26 12:38       ` Brian Drummond
replies disabled

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