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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!Xl.tags.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 01 Jan 2016 11:30:34 -0600 From: Dennis Lee Bieber Newsgroups: comp.lang.ada Subject: Re: New to Ada, why these warning messages? Date: Fri, 01 Jan 2016 12:30:38 -0500 Organization: IISS Elusive Unicorn Message-ID: <5fbd8blmdrlb9cpnjrj20edcttm8m0e68v@4ax.com> References: X-Newsreader: Forte Agent 6.00/32.1186 X-No-Archive: YES MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 108.79.218.6 X-Trace: sv3-zQNSzMf/mI8AoLqXnoq5CvQgO/gRexuRFGsJqSxqXywirqeGMgOMSFrorJK1NVjcOjIzUNcbCzfJRPN!lWEqn4zmb3xeXl2yFXHCi0QYoBB6PT34sJ1LBRlJlMgVTUIfb2roi3BzSmC7O2UUBA4TD0bMCIAO!XAq7VrgpvNDpG7R7pRNgTCmUJw== X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3843 Xref: news.eternal-september.org comp.lang.ada:28970 Date: 2016-01-01T12:30:38-05:00 List-Id: On Fri, 1 Jan 2016 02:19:41 +0000 (UTC), Dale Dellutri declaimed the following: > PNames: array(Paint) of String(1..6) := > ("Red ", "Green ", "Yellow", "Blue ", "Pink ", "Orange", >"Mauve ", > "Cherry", "Indigo", "Brown "); > Why? > for I in 1..N loop Ada FOR loop index variables are automatically declared and typed to match the range provided. Which, as others have mentioned, should really be defined as the 'range of the type, not some magic numbers. And that IS what the error messages were telling you... >gnatarr2.adb:54:08: warning: for loop implicitly declares loop >variable >gnatarr2.adb:54:08: warning: declaration hides "I" declared at line 24 > Put(PNames(A(I)) & " "); Without actually coding it, I'd think this could be replaced by put(Paint'Image(A(i)) & " "); meaning no need for the additional pnames array. Okay... 'Image needs work for the alignment C:\Users\Wulfraed\Ada\GnatArr 1 2 3 4 5 6 7 8 RED RED PINK BLUE ORANGE CHERRY INDIGO INDIGO BROWN ORANGE BROWN BROWN GREEN INDIGO INDIGO INDIGO BLUE BLUE BLUE BLUE BLUE BLUE BLUE BLUE [2016-01-01 12:24:35] process terminated successfully, elapsed time: 00.18s with GNAT.IO; use GNAT.IO; procedure Gnatarr is -- Just some values to play with, along with a conversion array. type Paint is (Red, Green, Yellow, Blue, Pink, Orange, Mauve, Cherry, Indigo, Brown); -- The type of an array of paints, along with its size. N : constant := 8; type AType is array (Integer range 1 .. N) of Paint; -- Some Paint arrays. The first one is initialized with a list -- of colors. A : AType := (Red, Red, Pink, Blue, Orange, Cherry, Indigo, Indigo); B, C : AType; begin -- Use positions to set various values in various places. B := (5 => Green, 2 => Orange, 6 .. 8 => Indigo, 1 | 3 | 4 => Brown); -- Set the entire array to Blue. C := (others => Blue); -- Print the position numbers, spaced out to align with the -- the printouts of each of the arrays below. for I in AType'Range loop Put (" "); Put (I); Put (" "); end loop; New_Line; -- Print out the contents of each of A, B, and C. for I in AType'Range loop Put (Paint'Image (A (I)) & " "); end loop; New_Line; for I in AType'Range loop Put (Paint'Image (B (I)) & " "); end loop; New_Line; for I in AType'Range loop Put (Paint'Image (C (I)) & " "); end loop; New_Line; end Gnatarr; -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/