Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #31159

Re: Quick Question

From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Quick Question
Date 2015-02-19 16:22 -0500
Organization A noiseless patient Spider
Message-ID <mc5k5m$24c$1@dont-email.me> (permalink)
References <3490bff6-aabd-48ca-98c7-0de64d59b9fa@googlegroups.com>

Show all headers | View raw


On 2/19/2015 3:55 PM, Doug Mika wrote:

">" Hello, Usenet! I still haven't learned how to write
">" a useful Subject line!  Love and kisses, Doug.

> What is inside this for statement?  How else could we have written the for-statement?
>
> for(Card card : c){
>     deckArrayList.remove(card);
>     this.remove(card);
>     this.repaint();
> }

     I *think* your first question is about the stuff between
the first set of parentheses (although the precise meaning of
"inside" isn't clear to me).  Perhaps you are surprised not to
see the usual three pieces separated by semicolons, now known
as the "basic for statement" (JLS 14.14.1).

     Depending on what `c' is (you've kept that information to
yourself, for reasons that again are not clear), there are at
least two other ways to write the loop:

     - If `c' is an `Iterable<Card>', we can write

	for (Iterator<Card> it = c.iterator(); it.hasNext(); ) {
	    Card card = it.next();
	    // remainder of loop body
	}

     - If `c' is an array of `Card', we can write

	for (int i = 0; i < c.length; ++i) {
	    Card card = c[i];
	    // remainder of loop body
	}

     (Actually, the second rewrite isn't *quite* equivalent to the
original, but it's equivalent unless the loop body makes `c' refer
to a different array while executing.)

     Any Java textbook written in the last decade or thereabouts
will explain this.

     ... and this is the *last* answer you will get from me until
and unless you start using better Subject lines!

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Quick Question Doug Mika <dougmmika@gmail.com> - 2015-02-19 12:55 -0800
  Re: Quick Question Joerg Meier <joergmmeier@arcor.de> - 2015-02-19 22:03 +0100
  Re: Quick Question Leif Roar Moldskred <leifm@huldreskog.localdomain> - 2015-02-19 15:09 -0600
  Re: Quick Question Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-02-19 16:22 -0500

csiph-web