This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Problem with for-each loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with for-each loop" Watch "Problem with for-each loop" New topic
Author

Problem with for-each loop

Pan Niko
Ranch Hand

Joined: Mar 19, 2011
Posts: 86

Hello,
Is the first time that im using for-each loop so i dont know what im doing wrong. I have a 2-D array that i want to scan to find some elements. So i create a class Coordinate() that takes two integers (row, column) and addCoordinate() method where each variable added to itself.


Pawn starting always at the bottom of theArray (the last row of the array) For example if is starting on theArray[15][2] (Stone) and at theArray[10][2] there is another Stone and between them there ara Bridge elements then sets

but if standing on theArray[10][2] then

So starting and ending points are the same object. I cant understand why?
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

I'm not sure I understand your question that clearly, is there anyway you could post an example of your problem that compiles so we can test it. Also you are not using a 2d array, you are using a 1d array that has objects inside it.

Hunter


"If the facts don't fit the theory, get new facts" --Albert Einstein
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37897
    
  22
That sounds as though you should provide bindings from one Coordinate to the next. It looks almost as though you had a tree, rather than an array. You should traverse trees differently from arrays.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with for-each loop
 
Similar Threads
2D array
Need help on animation using GUI Builder.
I cant find the mistake
Calling a method
June Newsletter Puzzle