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,fd3a5ba6349a6060 X-Google-Attributes: gid103376,public From: Matthew Heaney Subject: Re: should I be interested in ada? Date: 1999/02/19 Message-ID: #1/1 X-Deja-AN: 445918314 Sender: matt@mheaney.ni.net References: <7a72e6$g55$1@probity.mcc.ac.uk> <7afttr$7v3$1@nnrp1.dejanews.com> <7aganu$qsc$1@plug.news.pipex.net> <36CC11A1.C7A71642@hercii.mar.lmco.com> <7ai8ji$q8q$1@remarQ.com> NNTP-Posting-Date: Thu, 18 Feb 1999 18:16:30 PDT Newsgroups: comp.lang.ada Date: 1999-02-19T00:00:00+00:00 List-Id: fraser@nospam.com writes: > In fact, one of my favourite things about Ada is the various ways in > which you can specify a range. I generally pick the lowest one on the > following list that's available in the context: > > for I in 1 .. 10 loop > for I in Low .. High loop Perhaps I'm being pedantic, but I don't recommend these forms. It's better to try to assert the type somehow. I sometimes see this: for I in 1 .. 10 loop ... Array_Object (I) ... end loop; but this makes me cringe. Yes, I know the type of index I "defaults" to Integer, but I'd rather you state that fact explicitly: for I in Positive range 1 .. 10 loop If you use this technique, you avoid the esoterica like for I in -1 .. 10 loop that wouldn't compile in Ada83. Just do this instead: for I in Integer range -1 .. 10 loop and all is well, no matter which version of the language you're using. The only time I like to use the form for I in 1 .. 10 loop is when I need to do some work that number of times, and I'm not actually using index in the body of the loop. Maybe a better choice of loop index name is for Count in 1 .. 10 loop to emphasize that this is not an array index. > for I in Discrete_Type loop > for I in Array_Type'Range loop > for I in Array_Object'Range loop I like these better. > (I think I read this in the Quality and Style Guide). Well, yet another guideline in that book I disagree with.