From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,63043e3a9a3d050f,start X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!e14g2000yqe.googlegroups.com!not-for-mail From: Ada novice Newsgroups: comp.lang.ada Subject: loop problem with exit condition Date: Sun, 26 Sep 2010 01:14:10 -0700 (PDT) Organization: http://groups.google.com Message-ID: <3087f399-2cae-4bc8-bba1-e728943473bb@e14g2000yqe.googlegroups.com> NNTP-Posting-Host: 193.11.22.91 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1285488850 20344 127.0.0.1 (26 Sep 2010 08:14:10 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 26 Sep 2010 08:14:10 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: e14g2000yqe.googlegroups.com; posting-host=193.11.22.91; posting-account=Rr9I-QoAAACS-nOzpA-mGxtAlZ46Nb6I User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10 (.NET CLR 3.5.30729),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:14263 Date: 2010-09-26T01:14:10-07:00 List-Id: 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..