Lesson 5.6:

C# Nested Loop - with programming example


Objective

What is Nested Loop in c#?
How to Write Nested Loop?
Programming example

What is nested loop in c#?

A loop inside a loop is called nested loop. It is very useful when working on multidimensional array. You can use many loop as nested.

While(true) Loop

Programming Example

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace nested_loop
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 1; i <= 10; i++)
            {
                for (int j = 1; j <= 10; j++)
                {
                    Console.Write("\t"+i * j);
                }
                Console.WriteLine();
            }
            Console.ReadKey();
        }
    }
}


		  

Output

12345678910
2468101214161820
36912151821242730
481216202428323640
5101520253035404550
6121824303642485460
7142128354249566370
8162432404856647280
9182736455463728190
102030405060708090100
__

Summary

In this chapter you have learned what nested loop is and how to use it in your program. In the next chapter you will get some programming exercises. You must clear before moving to next lesson.

BackNext