title: Javascript 2d for loop doesn't iterate through the final value of the outer loop
body: <p>I have a for loop that behaves differently depending on what type of input it has. The logic that changes its behavior can't effect the problem that I am having. Here is my code, then I will explain the problem.</p>
  <pre><code>propagateForward(input)
      {
          for(let i = 0; i &lt; input.length; i++)
          {
              this.NN[0][i] = input[i];
          }
  
          for(let i = 0; i &lt; this.NN.length-1; i++)
          {
              //The problem occurs between the next two console.logs when the neural network is not
              //the Actor agent, but is instead the critic agent. In the console &quot;outside&quot; will print
              //and &quot;inside&quot; won't print. Whereas they both should print.
              if(i == this.NN.length-2 &amp;&amp; !this.isActor) console.log(&quot;outside&quot;);
              for(let j = 0; j &lt; this.NN[i+1].length-1; j++)
              {
                  if(i == this.NN.length-2 &amp;&amp; !this.isActor) console.log(&quot;inside&quot;);
                  var weightsSum = 0;
                  for(let r = 0; r &lt; this.NN[i].length; r++)
                  {
                      if(r == this.NN[i].length-1 &amp;&amp; i != 0) 
                      {
                          weightsSum += this.NN[i][r];
                      }
                      else
                      {
                          var NodeVal = this.NN[i][r];
                          weightsSum += this.weights[i][r][j] * NodeVal;
                      }
                  }
                  if(i == this.NN.length-2) 
                  {
                      if(!this.isActor) console.log(weightsSum);
                      this.NN[i+1][j] = weightsSum;
                  }
                  else
                  {
                      if(this.isActor) this.NN[i+1][j] = tanh(weightsSum);
                      else
                      {
                          this.NN[i+1][j] = ReLU(weightsSum);
                      }
                  }
              }
          }
          if(this.isActor)
          {
              this.NN[this.NN.length-1] = softMax(this.NN[this.NN.length-1]);
          }
          return this.NN[this.NN.length-1];
      }
  </code></pre>
  <p>It is the propagate forward for a neural network. This question is related to my bug with the for loop and not have anything to do with NN. I need to calculate the last layer of the Critic neural network, but 'i' will not loop to i = 2 which is the last possible idx inside of the inner loop. I have console log on the outside. When I run the program it only detects i = 2 on the outside loop, but can't access it on the inside loop. Thus the console of my program reads:</p>
  <pre><code>outside
  outside
  outside
  outside
  outside
  outside
  outside
  outside
  outside
  outside
  ...
  </code></pre>
  <p>I want it to say outside and inside.</p>
  <p>The only thing in between the two points where I am printing the same information from and getting different results is the declaration of the inner for loop. It works fine when the boolean this.isActor = true (It calculates the actor network just fine). The boolean this.isActor is the only difference between when it works and doesn't work. Neither of the console.log lines where I am testing are being affected by any if statements.</p>
  <p>Given that this.NN.length = 4
  Question: Why is the inner for loop not able to access i = 2, but the outer for loop can access i = 2?</p>