title: conditions in random walk algorithm
body: <p>I'm a beginner in programming and I have been assigned a mini-project. the instructor was very unclear as to what I should exactly do. All I know is that it's a "random walk" and I should not be using a method, I only have to use loops, branching and random number generators (not even sure about this one). It should also receive a number of steps from the user and walk according to the given number. 
  anyways, I am a beginner with a very limited knowledge of C#. I have researched a lot, here and also in many other places, with no success. the codes are either very complex or are in other languages. 
  I have written a bit of the code. I don't know if it's correct. 
  please give me some pointers. 
  There are no errors but the program does not work, there is a problem with the conditions. </p>
  
  <pre><code> static void Main(string[] args)
      {
          int row = 100;
          int col = 100;
          int[,] matrix;
          matrix = new int[row, col];
          int n;
          Console.WriteLine("Enter the number of steps:");
          n = int.Parse(Console.ReadLine());
          const int up = 1;
          const int down = 2;
          const int left = 3;
          const int right = 4;
          int number=0;
          for (int i=0;i&lt;100;i++)
          {
              for (int j = 0; j &lt; 100; j++)
                  matrix[i, j] = number;
          }
          Random randomdirection = new Random();
          for (int counter = 0; counter &lt; n; counter++)
          {
              int direction = randomdirection.Next(1, 5);
              while (direction == 1)
              {
                  if ((++col) &lt; 100 &amp;&amp; matrix[row, ++col] == 0)
                  {
                      matrix[row, ++col] = ++number;
                  }
                  else
                      break;
              }
              while (direction == 2)
              {
                  if ((--col) &lt; 100 &amp;&amp; matrix[row, --col] == 0)
                  {
                      matrix[row, --col] = ++number;
                  }
                  else
                      break;
              }
              while (direction == 3)
              {
                  if ((--row) &lt; 100 &amp;&amp; matrix[--row, col] == 0)
                  {
                      matrix[--row, col] = ++number;
                  }
                  else
                      break;
              }
              while (direction == 4)
              {
                  if ((++row) &lt; 100 &amp;&amp; matrix[++row,col] == 0)
                  {
                      matrix[++row,col] = ++number;
                  }
                  else
                      break;
              }
          }
          for (int i = 0; i &lt; row; i++)
          {
              for (int j = 0; j &lt; col; j++)
                  Console.WriteLine(matrix[i, j]);
          }
          Console.ReadKey();
      }
  </code></pre>
  
  <p>This is the assignment: 
  A drunkard begins walking aimlessly, starting at a lamp post. At each time step, the drunkard forgets where he or she is, and takes one step at random, either north, east, south, or west, with probability 25%. How far will the drunkard be from the lamp post after N steps? 
  It's very incomplete. 
  we have not been taught classes and methods so logically we should not use them. the point I think is to use arrays and loops and branching. 
  I did write the code myself. that's why it's so messed up.</p>
  
  <p>changed it to this: 
  seems like I don't see the problem :((</p>
  
  <pre><code> static void Main(string[] args)
      {
          Random randomObject = new Random();
          int randomDirection;
          int[,] mainarray;
          int row=10;
          int col=10;
          mainarray=new int[row,col];
          int number=0;
          for (int b=0;b&lt;row;b++)
          {
              for (int c=0;c&lt;col;c++)
                  mainarray[b,c]=number;
          }
  
          while (true)
          {
              int n;
              Console.WriteLine("Enter the number of steps: ");
              n = Convert.ToInt32(Console.ReadLine());
              for (int i = 0; i &lt; n; i++)
              {
                  randomDirection = randomObject.Next(1, 5);
                  if (randomDirection == 1 &amp;&amp; row &lt; 0 &amp;&amp; row &lt; 10)
                      mainarray[++row, col] = ++number;
                  if (randomDirection == 2 &amp;&amp; row &lt; 0 &amp;&amp; row &lt; 10)
                      mainarray[--row, col] = ++number;
                  if (randomDirection == 3 &amp;&amp; col &lt; 0 &amp;&amp; col &lt; 10)
                      mainarray[row, ++col] = ++number;
                  if (randomDirection == 4 &amp;&amp; col &lt; 0 &amp;&amp; col &lt; 10)
                      mainarray[row, --col] = ++number;
              }
              for (int i = 0; i &lt; row; i++)
              {
                  for (int j = 0; j &lt; col; j++)
                      Console.Write(mainarray[i,j]);
              }
          }
          Console.ReadKey();
      }
  </code></pre>