For loop in the form of : "for (A b : c)" in Java

for-loop, foreach, java, loops

Solution

It's a for each loop. You could also write it like this:

for(int i = 0; i < successors.size(); i++) {
    Node son = successors.get(i);
}

Though the only time I'd personally do that is when the index is needed for doing something other than accessing the element.

Problem

This is the first time that I've seen this kind of syntax : ``` // class Node public class Node { ... ... } public class Otherclass { ... } Otherclass graph = new Otherclass(); // getSuccessors is a method of Otherclass class Node currentNode ; List<Node> successors = graph.getSuccessors(currentNode); // weird for loop for (Node son : successors) { // do something } ``` What is that for loop ? some kind of a Matlab syntax ? Is there any other way to write that for loop ? Regards

Original source

Related problems