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