Pls help me code a for-loop & do-while loop in a multiplication ta

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 2069 Views - Last Post: 20 November 2015 - 05:28 AM Rate Topic: -----

#1 PLC808   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 19-September 15

Pls help me code a for-loop & do-while loop in a multiplication ta

Posted 08 November 2015 - 03:08 PM

Hello, 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.

I am simply supposed to modify some of the code (I already wrote some) by modifying the nested while-loops into nested for-loops. and also modify the nested while-loops into do-while loops. Loops are obviously very important parts of programming, but I think I seem to learn differently and am wondering what is missing...

Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;

//CS10b by Your Name

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 < 10)
            {
                //Inner loop goes across the columns
                c = 1;    //initialize c
                while (c < 10)
                {
                    intResult = r * c;

                    if (intResult < 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 < 10)
                        strSpace = "  ";  //two spaces 
                    else
                        strSpace = " ";   //one space
                    txtTable.AppendText(strSpace); // insert space

                    txtTable.AppendText(intResult.ToString());  //insert result
                    //increment c
                } //while (c < 10);

                txtTable.AppendText("\r\n");  //Move down one line
                //increment r
            } //while (r < 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 < 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


Any help would be much appreciated, thank you.

Is This A Good Question/Topic? 0
  • +

Replies To: Pls help me code a for-loop & do-while loop in a multiplication ta

#2 Damage   User is offline

  • Lord of Schwing
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,989
  • Joined: 05-June 08

Re: Pls help me code a for-loop & do-while loop in a multiplication ta

Posted 08 November 2015 - 03:41 PM

so which part of that's got you confused?
Was This Post Helpful? 0
  • +
  • -

#3 PLC808   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 19-September 15

Re: Pls help me code a for-loop & do-while loop in a multiplication ta

Posted 08 November 2015 - 03:47 PM

Just trying to figure out the best way of changing the while-loop into a do-while loop and the while-loop into a for-loop. Thank you.
Was This Post Helpful? 0
  • +
  • -

#4 Damage   User is offline

  • Lord of Schwing
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,989
  • Joined: 05-June 08

Re: Pls help me code a for-loop & do-while loop in a multiplication ta

Posted 08 November 2015 - 08:03 PM

well the logic behind it would be

a while loop checks for the condition at the beginning of the loop. So if sky = blue then do something. So theres a chance that the loop may never run, if for example the sky is grey.
a do while loop checks for the condition at the end of the loop. So do something then check if sky = blue. If sky = blue then run again but if sky = grey exit loop.

See the difference? do-while always executes at least once.

A while and a for, well they're pretty similar in that they check for the condition and then execute. A for loop controls the expression in it's declaration

for(int i =0; i<10;i++)
{
blah blah blah
}



instead of creating your variable it before your loop and changing it inside your loop like you'd do inside a while
int i = 0;

while(i<10)
{
 blah blah blah
 i = i + 1;
}


This post has been edited by Damage: 08 November 2015 - 08:03 PM

Was This Post Helpful? 2
  • +
  • -

#5 PLC808   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 19-September 15

Re: Pls help me code a for-loop & do-while loop in a multiplication ta

Posted 09 November 2015 - 09:55 PM

Thanks for the tips, working on it now. However, the do-while loop kind of confuses me because I am not exactly sure about things such as where to put the "do" in the current code. Definitely need to finish this tonight, but also need to get better at loops since I am horrible at them.
Was This Post Helpful? 0
  • +
  • -

#6 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: Pls help me code a for-loop & do-while loop in a multiplication ta

Posted 10 November 2015 - 08:26 AM

Conceptually, a loop does exactly what it says it does. It "loops".

The various different loops are just variations on how the looping is done. I'll try to give a simple explanation and hopefully that will help. Just giving you the code isn't a useful learning tool.

while loops
The simplest of the loops. A while loop is essentially a repeating if statement. There's a condition at the top. It tests the condition. If it results in true, the loop body executes. If not, it is skipped. If the body does execute, it returns to the top and rechecks the condition. Thus: loop.

Example:

int i = 0;
while(i < 10)
{
  Console.WriteLine("i is {0}", i);
  i = i + 1;
}


The condition checks to see if i is less than 10. If so, it prints the value of i. When i gets greater than or equal to 10, the loop body is then skipped and the condition no longer tested.

do/while loop
Almost identical to the while loop. The one difference is, the test is moved to the bottom of the loop instead of the top. Instead of checking then running the loop body, the do/while loop runs the loop body, then checks the condition. The practical result of this is that a do/while loop is always executed once, where a while loop can fail the test and not run at all.

Example:
int i;
Random r = new Random();
do
{
	i = r.Next(0, 6) + 1;
	Console.WriteLine("i is {0}", i);
} while (i != 6);


This code generates random numbers between 1 and 6 inclusive (i.e. a dice roll). If the number is 6, the condition will return false and the loop will not repeat. However, the loop body is guaranteed to run once.

for loop
This loop is somewhat confusing because it includes a range variable. The idea is, if you want a loop that also "counts", the for loop is the one you want.

Example first this time:

for (int i = 0; i < 10; i++)
{
	Console.WriteLine("i is {0}", i);
}


So, there are three expressions as part of the for loop:

  • variable declaration
  • test
  • iteration


Variable declaration: declare your variable. If it's a pre-existing variable, you can leave this completely blank and just start with a semicolon. You probably shouldn't do that, but it's possible.

Test: the middle piece is basically what you put in the while expression in the other loops. When this expression is true, the loop body executes. When not, it is skipped and the code moves on. Like the while loop, the test is run before the loop body executes.

Iteration: this is run after the loop body executes. This typically modifies the range variable you declared in the first expression. The idea is, this is where you do the counting.

The previous example was about the most basic for loop. It's identical to the example we gave for the while loop even.
Was This Post Helpful? 4
  • +
  • -

#7 PLC808   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 19-September 15

Re: Pls help me code a for-loop & do-while loop in a multiplication ta

Posted 10 November 2015 - 09:16 PM

Thanks for all of the help. This is what I have so far but it has a lot of errors:

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
            int r = 1; //initialize r
            do (r < 10);
            
            {
            
                //Inner loop goes across the columns
                int c = 1; //initialize c
                do
                {

                } while (c < 10);
                    
                } while (r < 10);

                    if (intResult < 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("\r\n"); 

            //Outer loop goes down the rows
            //initialize r
            //do

            //Inner loop goes across the columns
            //initialize c
            //do
            for (int r = 1; r < 10; r++)
            {
                for (int c = 1; c < 10; c++)
                {
                    intResult = r * c;
                    if (intResult < 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
            }
        }


        //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("\r\n"); 


            //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 < 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


I am trying to fix it myself, but any more tips would be much appreciated.
Was This Post Helpful? 0
  • +
  • -

#8 PLC808   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 19-September 15

Re: Pls help me code a for-loop & do-while loop in a multiplication ta

Posted 10 November 2015 - 10:18 PM

I was unable to edit my previous post, so please disregard it. Again, I REALLY appreciate the help and I think I cleaned it up a bit but there are still errors... Mainly said "intResult" and "strSpace" are undeclared?

//CS10b by Your Name

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
            do
            {
                  } while (c < 10);
                //Inner loop goes across the columns
                c = 1; //initialize c
                do
                {
                
                } while (c < 10);
                
               do
               {
           
                 } while (intResult < 10);
                  
                    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("\r\n"); 

            //Outer loop goes down the rows
            //initialize r
            //do

            //Inner loop goes across the columns
            //initialize c
            //do
            for (int r = 1; r < 10; r++)
            {
                for (int c = 1; c < 10; c++)
                {
                    intResult = r * c;
                    if (intResult < 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
            }
        }


        //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("\r\n"); 


            //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 < 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

Was This Post Helpful? 0
  • +
  • -

#9 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: Pls help me code a for-loop & do-while loop in a multiplication ta

Posted 11 November 2015 - 08:30 AM

Please...we're not mind readers. Exception messages aren't magic. We need to know the exact message and line that threw it. Seriously, help us help you. If I told you "my car is making a funny noise", do you think the mechanic would know what's wrong with it without hearing the noise himself? And knowing the conditions that cause the noise?

Either way, in your ]btnWhileLoop_Click method, you're using those variables before you've initialized them. You've declared them, but you haven't assigned them a value.

That aside, you have a bunch of other problems with your code in that need fixing as well. You've got two back-to-back empty do/while loops inside your do/while loop in that same method, and a third that isn't back-to-back.
Was This Post Helpful? 0
  • +
  • -

#10 PLC808   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 19-September 15

Re: Pls help me code a for-loop & do-while loop in a multiplication ta

Posted 11 November 2015 - 07:04 PM

Sorry about that, I should have been more specific. The error repeatedly says,

Quote

"Error 2 Expected class, delegate, enum, interface, or struct"


I truly appreciate the help, but getting a bit discouraged and thinking of turning it in with errors if I cannot figure it out tonight.It should be simple.
Was This Post Helpful? 0
  • +
  • -

#11 PLC808   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 19-September 15

Re: Pls help me code a for-loop & do-while loop in a multiplication ta

Posted 11 November 2015 - 07:21 PM

Better?

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
            do
            {
                  } while (r < 10);
                //Inner loop goes across the columns
                c = 1; //initialize c
                do
                {
                
                } while (c < 10);

                intResult = r * c;
               do
               {
           
                 } while (intResult < 10);
                  
                    strSpace = "  ";

                    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("\r\n"); 

            //Outer loop goes down the rows
            //initialize r
            //do

            //Inner loop goes across the columns
            //initialize c
            //do
            for (int r = 1; r < 10; r++)
            {
                for (int c = 1; c < 10; c++)
                {
                    intResult = r * c;
                    if (intResult < 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
            }
        }


        //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("\r\n"); 


            //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 < 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

Was This Post Helpful? 0
  • +
  • -

#12 PLC808   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 19-September 15

Re: Pls help me code a for-loop & do-while loop in a multiplication ta

Posted 11 November 2015 - 07:51 PM

Can a Moderator please delete some of my posts? I hate wasting so much space. I finally got it to appear bug-free, but I am sure that there are still issues with it. Visual Studio keeps freezing on me, especially when I click the
"while loop" button; the "do loop" seems to be working fine, but the "for loop" button does nothing but remains at "0". Any tips? I think it is almost done thanks to you fine gentlemen. Updated 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
            do
            { 
                //Inner loop goes across the columns
                c = 1; //initialize c
                do
                {
                
                } while (c < 10);
            
            } while (r < 10);
            
                intResult = r * c;
               do
               {
           
                 } while (intResult < 10);
                  
                    strSpace = "  ";

                    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("\r\n");

            //Outer loop goes down the rows
            //initialize r
            //do

            //Inner loop goes across the columns
            //initialize c
            //do
            for (r = 1; r < 10; r++)
            {
                for (c = 1; c < 10; c++)
                {
                    intResult = r * c;
                    if (intResult < 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
                }
            }
        }


        //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("\r\n"); 


            //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 < 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

Was This Post Helpful? 0
  • +
  • -

#13 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7187
  • View blog
  • Posts: 24,357
  • Joined: 05-May 12

Re: Pls help me code a for-loop & do-while loop in a multiplication ta

Posted 12 November 2015 - 07:01 AM

In general, we don't delete posts because helps people see the progression of the code and/or idea. Somebody coming late into the topic can see what has happened, and for some other student in the distant future who runs across the post, they can see how a program evolves towards a solution. Very rarely is there a program that just comes about from a "big bang", as much as textbooks make it look. It encourages students to see things really work in the real world.

Your program "freezes" because it is in an infinite loop on lines 27-31. When does c ever change values to make the condition false and break out of the loop?
Was This Post Helpful? 0
  • +
  • -

#14 Curtis Rutland   User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5106
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: Pls help me code a for-loop & do-while loop in a multiplication ta

Posted 12 November 2015 - 09:10 AM

You've still got several empty do/while loops. Empty loops are pointless loops; if there's nothing inside the { }, then nothing happens several times. You see how that's undesirable?

Maybe that's the problem, knowing what's inside a loop and what's outside:

do  //loop starts here
{
  //everything in between the { and the } is repeated.
  //it's "inside" the loop body
} while (someCondition); //this is the end, and the condition check
//this is outside the loop, and will only be executed once the loop is finished looping


Was This Post Helpful? 0
  • +
  • -

#15 PLC808   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 19-September 15

Re: Pls help me code a for-loop & do-while loop in a multiplication ta

Posted 12 November 2015 - 07:42 PM

View PostSkydiver, on 12 November 2015 - 07:01 AM, said:

In general, we don't delete posts because helps people see the progression of the code and/or idea. Somebody coming late into the topic can see what has happened, and for some other student in the distant future who runs across the post, they can see how a program evolves towards a solution. Very rarely is there a program that just comes about from a "big bang", as much as textbooks make it look. It encourages students to see things really work in the real world.

Your program "freezes" because it is in an infinite loop on lines 27-31. When does c ever change values to make the condition false and break out of the loop?

Oh alright, good to know. I just thought I may have been annoying people by making repeat post. Helping others is a wonderful thing.

I think that one of the reasons why I am having so much trouble with it is because I am thrown off by "nested" loops and unfortunately my instructor never responds. All examples I see seem to be of normal loops and not nested. However I am still working on it along with my 3 other apps (which are a lot easier for me). Thanks again, gentlemen.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2