title: Print 2-d array in sprial order-entering infinite loop
body: <p>I am trying to implement print 2 d array in sprial order. I dont know why but my code is entering inside infinite for loop prints 1,2,3,4 repeatedly.</p>
  
  <p>StringsubString.java</p>
  
  <pre><code>package com.String;
  
  public class StringSubString {
  
      public static void main(String arg[]) {
          int[][] values = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}};
          printInSprialOrder(values, 4, 4);
      }
  
      private static void printInSprialOrder(int A[][], int m, int n) {
          int t = 0, b = m - 1, l = 0, r = n - 1;
          while (t &lt;= b &amp;&amp; l &lt;= r) {
              for (int i = l; i &lt;= r; i++) {
                  System.out.println(A[t][i]);
                  t++;
              }
              for (int i = t; i &lt;= b; i++) {
                  System.out.println(A[i][r]);
                  r--;
              }
  
              for (int i = r; i &gt;= l; i++) {
                  System.out.println(A[b][i]);
                  b--;
              }
              for (int i = b; i &gt;= t; i--) {
                  System.out.println(A[i][l]);
  
              }
          }
      }
  }
  </code></pre>