Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #31156 > unrolled thread
| Started by | Doug Mika <dougmmika@gmail.com> |
|---|---|
| First post | 2015-02-19 12:55 -0800 |
| Last post | 2015-02-19 16:22 -0500 |
| Articles | 4 — 4 participants |
Back to article view | Back to comp.lang.java.programmer
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
| From | Doug Mika <dougmmika@gmail.com> |
|---|---|
| Date | 2015-02-19 12:55 -0800 |
| Subject | Quick Question |
| Message-ID | <3490bff6-aabd-48ca-98c7-0de64d59b9fa@googlegroups.com> |
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();
}
Thanks
[toc] | [next] | [standalone]
| From | Joerg Meier <joergmmeier@arcor.de> |
|---|---|
| Date | 2015-02-19 22:03 +0100 |
| Message-ID | <1xudolm8kuvw5.1amw79pveznkl$.dlg@40tude.net> |
| In reply to | #31156 |
On Thu, 19 Feb 2015 12:55:14 -0800 (PST), Doug Mika wrote: > What is inside this for statement? Horribly inefficient code that removes all cards from a deck and some theorized gui element and pointlessly spams repaint. > How else could we have written the for-statement? There are near infinite ways to rewrite code, but possible correct answers to this obvious homework question would be a traditional for loop (for (int i = 0; i < card...) or moving the repaint out of the loop. Liebe Gruesse, Joerg -- Ich lese meine Emails nicht, replies to Email bleiben also leider ungelesen.
[toc] | [prev] | [next] | [standalone]
| From | Leif Roar Moldskred <leifm@huldreskog.localdomain> |
|---|---|
| Date | 2015-02-19 15:09 -0600 |
| Message-ID | <aeCdnddWvPNpzXvJnZ2dnUVZ8mGdnZ2d@giganews.com> |
| In reply to | #31156 |
Doug Mika <dougmmika@gmail.com> wrote: > What is inside this for statement? How else could we have written the for-statement? > Ask your teaching assistant. He's got a better idea of how your question relates to your assignment than we do. -- Leif Roar Moldskred
[toc] | [prev] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2015-02-19 16:22 -0500 |
| Message-ID | <mc5k5m$24c$1@dont-email.me> |
| In reply to | #31156 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web