Results 1 to 6 of 6
Thread: find first empty cell?
- 03-15-2011, 07:29 AM #1
Member
- Join Date
- Dec 2010
- Posts
- 22
- Rep Power
- 0
find first empty cell?
What i want to do is use a for-loop to find the first empty cell in a 2D array and put a value in it. However, my code applies the loop to all empty cells in the array. What am i doing wrong here?
Java Code:for (int row = 0; row < GRIDSIZE; row++) { for (int col = 0; col < GRIDSIZE; col++) { if (isEmpty(row, col) == false) { printIt(); } else { setCell(row, col, 1);
Any help would be appreciated.
- 03-15-2011, 08:01 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,380
- Blog Entries
- 7
- Rep Power
- 17
Break out of the loop when you've found an empty cell (and set a value in it):
Java Code:} else { setCell(row, col, 1); return; // or break; }When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-15-2011, 08:58 AM #3
Member
- Join Date
- Dec 2010
- Posts
- 22
- Rep Power
- 0
it still sets the value of more than one empty square. any other ideas?
edit: i got it to work. thanks anywayLast edited by truant420; 03-15-2011 at 09:21 AM.
- 03-15-2011, 09:35 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,380
- Blog Entries
- 7
- Rep Power
- 17
- 03-15-2011, 10:20 AM #5
Member
- Join Date
- Dec 2010
- Posts
- 22
- Rep Power
- 0
yeah, that was the case. thank you, Jos.
- 03-15-2011, 01:13 PM #6
Crossposted: find first empty cell?
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
Similar Threads
-
How to find out if part of an array is empty
By counterfox in forum New To JavaReplies: 2Last Post: 10-13-2010, 06:09 PM -
Empty Form?
By Vorfin in forum New To JavaReplies: 13Last Post: 07-04-2010, 11:54 PM -
Why is this stakc empty?
By jigglywiggly in forum New To JavaReplies: 1Last Post: 10-09-2009, 06:22 AM -
JXL Empty cell problem
By ironicending in forum New To JavaReplies: 1Last Post: 01-26-2009, 03:32 PM -
Empty ResultSet
By Java Tip in forum Java TipReplies: 0Last Post: 02-09-2008, 08:36 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks