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,ee01489f40ec6ec7,start X-Google-Attributes: gid103376,public From: davidf@worf.mks.com (David J. Fiander) Subject: Emulating Modula-3's FOR loop Date: 1996/07/07 Message-ID: <4rocup$rvo@ia.mks.com>#1/1 X-Deja-AN: 164140287 organization: Mortice Kern Systems Inc., Waterloo, Ontario, CANADA newsgroups: comp.lang.ada Date: 1996-07-07T00:00:00+00:00 List-Id: I just ran across something minor, but annoying. Suppose I've got an array, indexed by the type Subscript, and I want to operate on every n'th element of the array. In Modula-3, I'd say something like FOR i FROM n TO last BY n do (* process the array elements *) END; Now, if last is not divisible by n, this will still work, without raising a Constraint_Error (or the modula equivalent). But in Ada, the obvious translation procedure Operate(Arr: in out Array(Subscript) of Elt; N: in Subscript) is I: Subscript := N; begin while I <= Subscript'Last loop -- Process the array I := I + N; end loop; end Operate; will raise a Constraint_Error on the last addition. Is there a better way to deal with this than ... begin while I <= Subscript'Last loop -- process I := I + N; end loop; exception when Constraint_Error => null; end;