vendredi 13 mars 2015

Skip one element of enhanced for loop



While working with graphs I have found frequently I need to skip one element while looping. Is there a way do to this with out calling an if statement in each cycle of the loop?


example:



private void printAll(Node<T> root){
System.err.println(toString());
for(Node<T> node : links.values()){
if (node == root) continue;
node.printAll(this);
}
}


I suspect the answer is no, but would like to confirm.


EDIT: The question is, is there a way to iterate a data structure skipping one known element without using an if statement with an enhanced for loop or some other method.




Aucun commentaire:

Enregistrer un commentaire