Looping Structure in C#

Download
Download is available until [expire_date]
  • Version
  • Download 33
  • File Size 292.22 KB
  • File Count 1
  • Create Date March 1, 2016
  • Last Updated March 1, 2016

Looping Structure in C#

Looping Structure in C#

A step by step tutorials, source code and explanation on different looping structure in c#

C# Loops:

Do while loop
While loop
Foreach loop
For loop

Sample code:

private void Button1_Click(object sender, EventArgs e)
        {
            int myNumber=0;
            do
            {
                MessageBox.Show("number: " + myNumber,"do while loop");
                myNumber = myNumber + 1;
            } while (myNumber < int.Parse(TextBox1.Text));
        }

        private void Button2_Click(object sender, EventArgs e)
        {
            int myNumber = 0;
            while (myNumber < int.Parse(TextBox1.Text))
            {

                MessageBox.Show("number: " + myNumber, "while loop");
                myNumber = myNumber + 1;
            }
        }

        private void Button3_Click(object sender, EventArgs e)
        {

          int[] array1 = { 0, 1, 2, 3, 4, 5 };

          foreach (int n in array1)
          {
                MessageBox.Show("number: " + n, "foreach loop");            
           }
        }

        private void Button4_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < int.Parse(TextBox1.Text); i++)
            MessageBox.Show("number: " + i, "for loop");            
        }
, , , , ,

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.