Note that there are some explanatory texts on larger screens.

plurals
  1. POJava: Wrong variable increasing?
    primarykey
    data
    text
    <p>This little snippet of code for some reason isn't working properly. What this is supposed to do is make a move if <code>i</code> is less than <code>colLength</code>, which is 2 at this point meaning it should stop after typing in 7. And for some reason it keeps going until the end of the array.</p> <p>Why does it keep going? I don't have any bit of code that increments <code>r</code>? </p> <pre><code>//this is a 5 step process, this is the 4th if (stepMaker == 4 &amp;&amp; numLocation &lt; totalSteps){ //looking through the array for the last number used in step 3, this works for (int r = 0; r &lt; gridRow-1; r++){ for (int c = 0; c &lt; gridCol-1; c++){ // still looking //using 5 instead of numLocation works, numLocation keeps going however... why? if(grid[r][c] == (numLocation)) { int x = 1; for(int i = 0; i &lt; colLength; i++){ grid[r + x][c] = numLocation + 1; System.out.println("x=" + x + " // " + "numLocation=" + numLocation + " // " + "r=" + r + " // " + "c=" + c + " // " + "stepMaker=" + stepMaker + " // " + "colLength=" + colLength + " // " + "rowLength=" + rowLength); numLocation++; for (int xx = 0; xx &lt; gridRow; xx++){ for (int yy = 0; yy &lt; gridCol; yy++){ System.out.print(grid[xx][yy] + " "); } System.out.println(""); } x++; } } } } //colLength++; stepMaker++; } </code></pre> <p>And this is the output:</p> <pre><code>x=1 // numLocation=5 // r=2 // c=2 // stepMaker=4 // colLength=2 // rowLength=3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 4 3 0 0 0 0 6 1 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 x=2 // numLocation=6 // r=2 // c=2 // stepMaker=4 // colLength=2 // rowLength=3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 4 3 0 0 0 0 6 1 2 0 0 0 0 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 x=1 // numLocation=7 // r=4 // c=2 // stepMaker=4 // colLength=2 // rowLength=3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 4 3 0 0 0 0 6 1 2 0 0 0 0 7 0 0 0 0 0 0 8 0 0 0 0 0 0 0 0 0 0 0 x=2 // numLocation=8 // r=4 // c=2 // stepMaker=4 // colLength=2 // rowLength=3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 4 3 0 0 0 0 6 1 2 0 0 0 0 7 0 0 0 0 0 0 8 0 0 0 0 0 0 9 0 0 0 0 rowLength = 3 // colLength = 2 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload