Updated on Kisan Patel
The for
loop statement is one of the most widely used control statement. The for
loop executes a statement in the loop until the given condition is true.
The basic structure of a for
loop is –
for(initialization; condition; increments/decrements) { statement or block of code }
Lets take one example to understand how to use for loop in C# program.
using System; namespace ConsoleApp { class forloopDemo { static void Main(string[] args) { for (int i = 1; i <= 10; i++) { Console.WriteLine(i); } } } }
The output of the above C# program…
i
is initialized with the value of 1.i<=10
remains true.i++
by 1 each time the loop starts.