title: Sudoku generator algorithm using a recursive method
body: <p>I'm trying to create a Sudoku generator that saves the puzzle in a 2D string array.</p>
  
  <p>I created a recursive method that returns the puzzle at the end, but as soon as it returns the puzzle it continues with the recursion and so I can never break out of this method.</p>
  
  <p>The recursive method code is below:</p>
  
  <pre><code>    static string[,] RecursiveFill(int digit, int px, int py, string[,] grid)
      {
          // Create a new test grid
          string[,] testGrid = new string[9, 9];
  
          // Fill it with the current main grid
          for (int i = 0; i &lt; 9; i++)
          {
              for (int j = 0; j &lt; 9; j++)
                  testGrid[j, i] = grid[j, i];
          }
  
          // Place the digit to be entered into the test grid
          testGrid[px, py] = digit.ToString();
  
          // Find a new digit to enter
          for (int x = 0; x &lt; 9; x++) // Iterate through the grid by x
          {
              for (int y = 0; y &lt; 9; y++) // And by y
              {
                  if (testGrid[x, y] == 0.ToString() || testGrid[x, y] == null) // If an empty slot
                  {
                      for (int val = 1; val &lt;= 9; val++) // 1-9 as these are the numbers to enter
                      {
                          if (CheckMove(y, x, val, testGrid)) // If the move is valid
                              RecursiveFill(val, x, y, testGrid); // Use recursion and go back around
                      }
  
                      return null; // Otherwise return null
                  }
              }
          }
  
          return testGrid; // This gets returned but then it carries on with the RecursiveFill method and never exits this method?
      }
  </code></pre>
  
  <p>Here's how I'm calling this method:</p>
  
  <pre><code>    sudokuGrid = RecursiveFill(0, 0, 0, sudokuGrid);
  </code></pre>
  
  <p>If anyone has any suggestions as to what I need to modify in order to get this method to return a complete sudoku puzzle that'd be awesome. I've had this bug for a few days now and I can't figure out why. :/</p>