title: How to properly code a For-Loop and a Do-While Loop in a multiplication table in C#?
body: <p>I hate to be so helpless and by no means am I asking anyone to do my homework for me, but for some strange reason, I am having a hard time with this assignment and Loops in general have always given me a lot of trouble. But I am still a bit new at C# and OOP.</p>
  
  <p>I am simply supposed to modify some of the code (the instructor and I already wrote some) by modifying the nested while-loops into nested <strong>for-loops</strong>. and also modify the nested while-loops into <strong>do-while loops</strong>. Loops are obviously very important parts of programming, but I think I seem to learn differently and am wondering what is missing... </p>
  
  <p>Code:</p>
  
  <pre><code>namespace CS10b
  {
      public partial class frmCS10b : Form
      {
          public frmCS10b()
          {
              InitializeComponent();
          }
  
  
          private void btnWhileLoop_Click(object sender, EventArgs e)
          {
              int r = 0; //row
              int c = 0; //column
              int intResult;
              string strSpace;
  
              txtTable.Clear();    //clear the text box
              txtTable.Refresh();  //refresh the form before exiting the method
              Thread.Sleep(1000);  //wait one second to see the clear text box
  
              //Outer loop goes down the rows
              r = 1;   //initialize r
              while (r &lt; 10)
              {
                  //Inner loop goes across the columns
                  c = 1;    //initialize c
                  while (c &lt; 10)
                  {
                      intResult = r * c;
  
                      if (intResult &lt; 10)
                          strSpace = "  ";  //two spaces 
                      else
                          strSpace = " ";   //one space
                      txtTable.AppendText(strSpace); // insert space
  
                      txtTable.AppendText(intResult.ToString());  //insert result
                      c++;  //increment c
                  }
  
                  txtTable.AppendText("\r\n");  //Move down one line
                  r++;  //increment r
              }
          }
  
  
          //Modify the nested while loops used above to nested do-while loops
          private void btnDoWhileLoop_Click(object sender, EventArgs e)
          {
              int r = 0; //row
              int c = 0; //column
              int intResult;
              string strSpace;
  
              txtTable.Clear();    //clear the text box
              txtTable.Refresh();  //refresh the form before exiting the method
              Thread.Sleep(1000);  //wait one second to see the clear text box
  
              txtTable.AppendText("Nested do-while loops to be developed");  //Delete this after implementation
  
              //Outer loop goes down the rows
              //initialize r
              //do
              {
                  //Inner loop goes across the columns
                  //initialize c
                  //do
                  {
                      intResult = r * c;
  
                      if (intResult &lt; 10)
                          strSpace = "  ";  //two spaces 
                      else
                          strSpace = " ";   //one space
                      txtTable.AppendText(strSpace); // insert space
  
                      txtTable.AppendText(intResult.ToString());  //insert result
                      //increment c
                  } //while (c &lt; 10);
  
                  txtTable.AppendText("\r\n");  //Move down one line
                  //increment r
              } //while (r &lt; 10);
          }
  
  
          //Modify the nested while loops used above to nested for loops
          private void btnForLoop_Click(object sender, EventArgs e)
          {
              int r = 0; //row
              int c = 0; //column
              int intResult;
              string strSpace;
  
              txtTable.Clear();    //clear the text box
              txtTable.Refresh();  //refresh the form before exiting the method
              Thread.Sleep(1000);  //wait one second to see the clear text box
  
              txtTable.AppendText("Nested do-while loops to be developed");  //Delete this after implementation
  
  
              //Outer loop goes down the rows
  
  
  
              //for (initialize r; Boolean Condition, increment r)
               {
  
                  //Inner loop goes across the columns
                  //for (initialize c; Boolean Condition, increment c)
                  {
                      intResult = r * c;
  
                      if (intResult &lt; 10)
                          strSpace = "  ";  //two spaces 
                      else
                          strSpace = " ";   //one space
                      txtTable.AppendText(strSpace); // insert space
  
                      txtTable.AppendText(intResult.ToString());  //insert result
                  }
  
                  txtTable.AppendText("\r\n");  //Move down one line
              }
          }
  
  
          private void btnExit_Click(object sender, EventArgs e)
          {
              this.Close();
          }
  
  
      }//end of form
  }//end of namespace
  </code></pre>
  
  <p>This SHOULD be easy, but loops I have never done do-while and for-loops. Thank you.</p>