How To Use For Loop In C#

In this article, I will explain how the for Loop can be used in C#.
  • 2349


For loop is used to run a statement or a block of statements repeatedly until a specified condition has been reached. For loop is useful where you know in advance how many times you want the loop to iterate. The syntax for the For loop is as follows.


for (initializer; condition; iterator)





Initializer is the initialize clause in which the loop iterators are declared.


Condition contains a boolean expression that's evaluated to determine whether the loop should exit or should run again.


Iterator is to increment/decrement the value that is executed after each iteration.




using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

class WhileTest


    static void Main()


        int r = 1;

        int s = 10;

        int sum = 0;

        for (r = 1; r < 10; r++ )


            sum = r + s;

            Console.WriteLine(" value of sum is {0}", sum);






The output of following program


© 2020 DotNetHeaven. All rights reserved.