For Loop

For Loop
Rating: 5 - 1 Votes

For Loop

C#Today, we will talk about loops.   These loops help you to iterate through a collection object.  For example, if you want to get the items present in an array, you can simply make use of loops.  In C# language, there are 4 kind of loops.

  1. For.
  2. While.
  3. Do while.
  4. Foreach.

In this chapter, I will show you how to make use of for loop and in the later chapters, we will see how to make use of another loops.   Using for loop, we can initialize a local variable, add a certain condition to be met, and add an increment to that variable.  The for loop structure is given below.

A sample code is given below, where we are using a for loop to print out the items present in numbers array.  We are simply iterating through the items and using the array index to print out the value.