Nested loop in C#
When loops are used inside the other loops, it is known as nested loops.
we can use more than one loop inside any another while, for or do..while loop.
Example as follows.
using System;
namespace nested_loop
{
class Program
{
static void Main(string[] args)
{
/* loop within loop*/
for (int x = 1; x < 5; x++)
for (int y = 1; y < x; y++)
Console.WriteLine("Rohit Programming Zone");
Console.ReadLine();
}
}
}
Output
Rohit Programming Zone
Rohit Programming Zone
Rohit Programming Zone
Rohit Programming Zone
Rohit Programming Zone
Rohit Programming Zone
When loops are used inside the other loops, it is known as nested loops.
we can use more than one loop inside any another while, for or do..while loop.
Example as follows.
using System;
namespace nested_loop
{
class Program
{
static void Main(string[] args)
{
/* loop within loop*/
for (int x = 1; x < 5; x++)
for (int y = 1; y < x; y++)
Console.WriteLine("Rohit Programming Zone");
Console.ReadLine();
}
}
}
Output
Rohit Programming Zone
Rohit Programming Zone
Rohit Programming Zone
Rohit Programming Zone
Rohit Programming Zone
Rohit Programming Zone