Quantcast
Viewing all articles
Browse latest Browse all 40524

2d array and index looping

Hi,
What do you expect to happen in your second example?
I guess you want only a cell to turn yellow, the one at j+3.
You have to check the bounds of the array before adressing a cell.
For example:

// Only modify the cell i,j-3 if j-3 is a correct indice
if ( j-3 >=0 ) cells[i][j-3].setPossible(true);
// Only modify the cell i,j+3 if j+3 is a correct indice
if ( j+3 < COL ) cells[i][j-3].setPossible(true);

Using cells[i][j] in your code, without being sure that
0 <= i < ROW
and 0 <= j < COL
can produce unexpected behaviour, and crash the application.


Viewing all articles
Browse latest Browse all 40524

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>