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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,32b8be7d0d9988ed X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-09-29 11:49:50 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!nntp-relay.ihug.net!ihug.co.nz!west.cox.net!cox.net!newsfeed1.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread1.prod.itd.earthlink.net.POSTED!not-for-mail Message-ID: <3D974B39.6000800@acm.org> From: Jeffrey Carter User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.0.0) Gecko/20020530 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: "In reverse" in for loop acting weird. References: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Date: Sun, 29 Sep 2002 18:49:07 GMT NNTP-Posting-Host: 63.184.104.176 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.prod.itd.earthlink.net 1033325347 63.184.104.176 (Sun, 29 Sep 2002 11:49:07 PDT) NNTP-Posting-Date: Sun, 29 Sep 2002 11:49:07 PDT Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.ada:29415 Date: 2002-09-29T18:49:07+00:00 List-Id: gilrain wrote: > Hi all, > > Okay, my program is working perfectly except for this one minor detail. The > result (stored in a string) prints exactly backward. What's baffling me is > that it's still backward even when I reverse the process for building the > string. Here's the offending code segment: > > for j in reverse -15..15 loop > case integer(abs(coefficients(j))) is > when 0 => result(j+16) := '0'; > when 1 => result(j+16) := '1'; > when 2 => result(j+16) := '2'; > when 3 => result(j+16) := '3'; > when 4 => result(j+16) := '4'; > when 5 => result(j+16) := '5'; > when 6 => result(j+16) := '6'; > when 7 => result(j+16) := '7'; > when 8 => result(j+16) := '8'; > when 9 => result(j+16) := '9'; > when 10 => result(j+16) := 'A'; > when 11 => result(j+16) := 'B'; > when 12 => result(j+16) := 'C'; > when 13 => result(j+16) := 'D'; > when 14 => result(j+16) := 'E'; > when 15 => result(j+16) := 'F'; > when 16 => result(j+16) := 'G'; > when others => result(j+16) := '!'; > end case; > end loop; result(16) := '.'; > > Coefficients is an array of long floats which at this point in the program > only contains whole numbers. I want coefficients(15) to be the first > character in the string, and so on to -15. The above code prints it > backwards, but the thing which gets me is that taking out "reverse" doesn't > change the program output one bit! This little excerpt doesn't "print" anything, so understandably we're a little confused about what you're talking about. Something that shows the object and type declarations referenced, the output statements involved, the output obtained, and the output expected will likely get a more useful response. Of the snippet provided above, it appears that you will put the same values in result regardless of the order that you traverse Coefficients, whether normally, reverse, or some sort of non-repeating random selection. If the range of Coefficients is -15 .. 15, then your for loop would be better written as for J in [reverse] Coefficients'range loop In general, when working with arrays, it is rarely necessary to mention a magic number more than once. Once the magic number is used to define the range of the type or object, attributes, such as 'range above, eliminate the need to mention it again. When you do need to mention a magic number more than once, it's a good idea to make it a named number or constant. For example, the 16 in your code is a good candidate for this. I suspect it may be (Result'Length + 1) / 2. -- Jeff Carter "Nobody expects the Spanish Inquisition!" Monty Python's Flying Circus