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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,adbfb5b65308687,start X-Google-Attributes: gid103376,public From: stt@houdini.camb.inmet.com (Tucker Taft) Subject: Re: for-loop parameters Date: 1997/09/24 Message-ID: #1/1 X-Deja-AN: 275230856 Sender: news@inmet.camb.inmet.com (USENET news) References: X-Nntp-Posting-Host: houdini.camb.inmet.com Organization: Intermetrics, Inc. Newsgroups: comp.lang.ada Date: 1997-09-24T00:00:00+00:00 List-Id: CMSC 330-4021 Student 23 (cs330a23@nova.umuc.edu) wrote: : If a loop parameter in a for-loop statement should not be declared in the : variable declaration list, how can the compiler determine what type the : loop parameter belongs to? Thanks. The syntax for a "for" loop includes the ability to specify explicitly the type of the loop parameter. By default, it is determined by the type of the low and high bound, and if both are "universal" integers, then it uses Standard.Integer as a fallback. For example: for I in 1..10 loop -- uses Standard.Integer for MI in My_Integer range 1..10 loop -- uses My_Integer for J in An_Array'Range loop -- uses index subtype of An_Array for K in 1..N loop -- uses type of N (unless univesal, in which case -- uses Standard.Integer) for C in Red .. Green loop -- uses enum type of Red and Green (presuming there is only one such type with directly visible enumerals) for MC in My_Color range Red .. Green loop -- in case there are 2 or more -- enum types with directly visible -- enumerals Red and Green for X in F(Y) .. G(Z) loop -- uses result type of F and G etc... I would guess that in 98% of the cases, the explicit type can be left out, especially if you typically avoid having "magic" numeric literals scattered about in your code. See RM95 5.5(4) for the "for" loop syntax, and RM95 3.6(6,17-19) for the explanation of discrete_subtype_definition. -- -Tucker Taft stt@inmet.com http://www.inmet.com/~stt/ Intermetrics, Inc. Burlington, MA USA