Ask your own question, for FREE!
Computer Science 9 Online
OpenStudy (anonymous):

Java Which of the following statements is true? (2 Points) For-each loops can only be used to iterate over array elements. For-each loops can be used to iterate over all array elements in reverse order. For-each loops cannot be rewritten as for loops.

OpenStudy (woodrow73):

The functionality of a for each loop is to iterate through an array completely. ``` int[] x = {1, 2, 3, 4, 5, 6, 7, 8, 9}; for(int i : x) System.out.print(x + " "); ``` The above will print: ``` 1 2 3 4 5 6 7 8 9 ``` The loop automatically knows how many elements are in array x, and will iterate through each element of that array (starting at element 0, and moving up by 1 each iteration until the end). Within each iteration, the array's value at that particular iteration/element is passed onto the primitive datatype on the left of the colon; within the for each loop, you're free to do what you want with the values passed into the primitive data value.

OpenStudy (anonymous):

For-each doesn't just work for arrays. I believe it works for all classes that implement `Iterable`.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!