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,ad988eb0a9545c86 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-04-18 09:56:33 PST Path: supernews.google.com!newsfeed.google.com!newsfeed.stanford.edu!cyclone.bc.net!newsfeed.bc.tac.net!news.bc.tac.net!not-for-mail Sender: blaak@TORUS Newsgroups: comp.lang.ada Subject: Re: Problem trying to implement generics. References: <9b46dr$cd8$1@taliesin.netcom.net.uk> <9b6jtu$4is$2@taliesin.netcom.net.uk> <9b6m27$68e$1@taliesin.netcom.net.uk> <0JBB6.10484$FD1.1197250@news6-win.server.ntlworld.com> <9b7tce$laf$2@taliesin.netcom.net.uk> <3ADC4320.7ACA3DEC@averstar.com> <9bhoup$h9k$1@taliesin.netcom.net.uk> From: Ray Blaak Message-ID: Organization: The Transcend X-Newsreader: Gnus v5.6.42/Emacs 19.34 Date: 18 Apr 2001 09:55:48 -0700 NNTP-Posting-Host: 208.181.209.61 X-Complaints-To: news@bctel.net X-Trace: news.bc.tac.net 987612981 208.181.209.61 (Wed, 18 Apr 2001 09:56:21 PDT) NNTP-Posting-Date: Wed, 18 Apr 2001 09:56:21 PDT Xref: supernews.google.com comp.lang.ada:6979 Date: 2001-04-18T09:55:48-07:00 List-Id: "Ayende Rahien" writes: > "Tucker Taft" wrote in message > > Interestingly enough, the standard Iterator in Java > > uses: > > while (Iter.hasNext()) { > > X = Iter.next(); > > ... > > } > Why [not] use it like this? > for (;Iter.hasNext(); X = Iter.next() ){ > //do stuff > } > > Is much more readable, IMO. Because that is wrong :-). With the above for loop, the nth iteration has the value for iteration n-1. The first iteration has no value at all. I.e. it is equivalent to: while(Iter.hasNext()) { // ...do stuff with X... X = Iter.next(); } The .next() method returns the current value and sets the iterator to be at the next one. It does not return the next value per se. A correct for loop is: for(; Iter.hasNext(); ) { X = Iter.next(); // ...do stuff with X... } but that is redundant, so a while loop is better. -- Cheers, The Rhythm is around me, The Rhythm has control. Ray Blaak The Rhythm is inside me, blaak@infomatch.com The Rhythm has my soul.