enhanced-for-loop

Why doesn't this for-each loop work?

In this code, why isn't my array initialised as I want it to? Is the for-each loop not designed to do that, or am I just not using it correctly? int[] array = new int[5]; //initialise array -> Doesn't work! Array still full of 0's for(int i : array) i = 24; ...

iterating over map and array simultaneously in a for loop

I am having some trouble creating a for loop within a constructor to iterate over a map and an array at the same time. Here, it is indicated that this cannot be done with an enhanced for loop. I have something like this, which raises a compiler error. Basically, the class has a Map which I want to populate via the constructor which take...

Strange behavior in Javascript enhanced for...in loop

I am making a Javascript game with the canvas tag, and I am using an enhanced for loop to update the player positions. In brief: var actors = new Array(); var player = new Actor(0, 0, img); actors[0] = player; function update_positions() { //position 1 for(var a in actors) { //position2 a.xpos += a.xvel; ...

Java Enhanced For Loop

How would I write the following for loop using an enhanced for loop> int [] info = {1,2,3,4,5,6,7,8,9,10}; int i; for (i = 0; i < info.length; i++) { if ((i+1) % 10 == 0) System.out.println(info[i]); else System.out.println(info[i] + ", "); } ...

Enhanced for loop problem

Why is my enhanced loop not working? Vector<String> v = new Vector<String>(); v.add("one"); v.add("two"); v.add("three"); for(String str : v){ System.out.println(v); } ...

Java or Groovy equivalent of python for loop + izip

Hi, Does anyone know the java or groovy equivalent of a python for loop using izip? python example: for item_one, item_two in izip(list_one, list_two): I'd like to do the same in java or groovy Thanks ...

What does ":" mean in this Java statement?

for (Season time : Season.values() ) system.out.println (time+ "\t" + time.getSpan()); I see an example for enumeration using :. What does this mean? ...