adding a condition to the enhanced for loop
From: Jo Vermeulen (jo_at_lumumba.luc.ac.be)
Date: 05/31/04
- Next message: Gawnsoft: "Re: Inner classes use"
- Previous message: Piotr Galuszkiewicz: "Looking for 6. edition of "Core Java 2 vol.1 - Fundamentals""
- Next in thread: Raymond DeCampo: "Re: adding a condition to the enhanced for loop"
- Reply: Raymond DeCampo: "Re: adding a condition to the enhanced for loop"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 31 May 2004 11:40:28 +0200
Hello,
I was wondering if it's possible to add a condition to the enhanced for
loop. This is an example of an enhanced for loop:
LinkedList<MyClass> children = new LinkedList<MyClass>();
boolean found = false;
children.add(new MyClass("Extended"));
children.add(new MyClass("Enhanced"));
children.add(new MyClass("Embraced"));
for (MyClass c: children) {
if (c.getName().equals("Enhanced") {
found = true;
}
}
This loop would continue right to the end though, even if "Enhanced" was
found at the first element. I would like to build an extra condition into
the loop, stating that it must continue but only while !found (this means
found == false).
Any ideas how to do this? Or is it not possible with an enhanced for loop?
Should I use a normal loop, and iterate through the elements using an
Iterator?
Kind regards,
-- Jo Vermeulen Student Computer Science at the tUL email: jo@lumumba.luc.ac.be www: http://lumumba.luc.ac.be/jo
- Next message: Gawnsoft: "Re: Inner classes use"
- Previous message: Piotr Galuszkiewicz: "Looking for 6. edition of "Core Java 2 vol.1 - Fundamentals""
- Next in thread: Raymond DeCampo: "Re: adding a condition to the enhanced for loop"
- Reply: Raymond DeCampo: "Re: adding a condition to the enhanced for loop"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|