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-24 09:00:38 PST Path: newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!cpk-news-hub1.bbnplanet.com!cambridge1-snf1.gtei.net!news.gtei.net!inmet!not-for-mail From: Tucker Taft Newsgroups: comp.lang.ada Subject: Re: Problem trying to implement generics. Date: Tue, 24 Apr 2001 12:00:37 -0400 Organization: AverStar (formerly Intermetrics) Burlington, MA USA Message-ID: <3AE5A325.C2181953@averstar.com> 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> NNTP-Posting-Host: nebula.burl.averstar.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: inmet2.burl.averstar.com 988128038 9385 141.199.8.77 (24 Apr 2001 16:00:38 GMT) X-Complaints-To: usenet@inmet2.burl.averstar.com NNTP-Posting-Date: 24 Apr 2001 16:00:38 GMT X-Mailer: Mozilla 4.75 [en] (X11; U; SunOS 5.7 sun4u) X-Accept-Language: en Xref: newsfeed.google.com comp.lang.ada:6891 Date: 2001-04-24T16:00:38+00:00 List-Id: Ayende Rahien wrote: > > "Tucker Taft" wrote in message > news:3ADC4320.7ACA3DEC@averstar.com... > > > Interestingly enough, the standard Iterator in Java > > uses: > > while (Iter.hasNext()) { > > X = Iter.next(); > > ... > > } > > > > even though Java has functions with side effects (although > > in fact, only with side-effects on by-reference operands, > > since it has no parameter modes at all!). > > Why use it like this? > for (;Iter.hasNext(); X = Iter.next() ){ > //do stuff > } > > Is much more readable, IMO. Well this started a long series of responses... But the key thing to point out is that the for-loop doesn't work. You are assigning X a value too late to use it inside the first iteration of the loop. The third "part" of a for-loop header is only executed at the *end* of each loop iteration. When programming in C (or Java), I generally do use a "for" loop when it works, but this is one case where it definitely doesn't. -- -Tucker Taft stt@avercom.net http://www.averstar.com/~stt/ Chief Technology Officer, AverCom Corporation (A Titan Company) Burlington, MA USA (AverCom was formerly the Commercial Division of AverStar: http://www.averstar.com/services/ebusiness_applications.html)