Signup as a Tutor

As a tutor you can connect with more than a million students and grow your network.

What Is The Difference In For...Loop And Foreach Loop?

Neelam S.
02/08/2017 0 0

Loop is very important in C# Programing language. Loop is call iteration statement, loops are used for executing the repeated task.

 1. For...Loop:

The for…loop executes a statement or a block of statements repeatedly until a specified expression is false. For…loop contain the maximum and minimum bound value.

For…loop Declaration:

For (initialization, Condition, increment/decrement)



 Initialization like int i = 0; //minimum bound

Condition like i < 5; //maximum bound

Example of for…loop:

For(int i=0;i<=5;i++){



Example of for…loop with array:

Int[] a=new int[5]{10,20,30,40,50};

For(int i=0;i<5;i++)




The for…loop always start with integer value. Means initialization of for…loop is done with int.

2. Foreach loop:

The foreach loop is a group of embedded statements for each element in an array or an object collection. There is no need to specify the maximum and minimum bound value. In foreach loop we can assign integer, string, float, char any type of data.


Foreach loop declaration:

Foreach(datatype variable_name in collection_name)



Example 2:

Int[] x=new int[5]{3,4,5,6,7};

Foreach(int k in x)




Example 3 foreach loop with string:

String[] fruits=new string[5]{“Apple”,”Banana”,”Kiwi”,”Mango”,”BlueBerry”};

Foreach(string k in fruits)




Example 4: Foreach loop with float data:

Float[] data=new float[3]{3400.56f,2000.53f,7800.23f};

Foreach(float k in data)




0 Dislike
Follow 0

Please Enter a comment


Other Lessons for You

"foreach" loop in C#
foreach is a looping statement : repeats a group of statements for each element in an array or an object collection. (or) used to iterate through the collection/ an array to get the required information. Advantages: Easy...

Raga Deepthi G. | 30 Mar

3 0
A very brief introduction to .NET framework
.NET development has started in the year 2000 , a product of Microsoft. From the begining of .NET development till now, it has got many RAD [ rapid application development ] facilities. Why .NET? developed...

Raga Deepthi G. | 27 Mar

2 0
OOPs Concepts
Session Objectives: Discuss the following: Drawbacks of traditional programming Need for Object: Oriented approach Object: Oriented techniques Discuss Object: Oriented Concepts Objects. Classes. Abstraction. Inheritance. Encapsulation. Polymorphism. Need...

Samir Bhogayta | 03 Jan

0 0
.NET With AngularJS Training Program Syllabus
What You will Learn in .NET with AngularJS Training Program? Introduction to .Net: Features of .Net, CTS, CLS, CLR and MSIL. C# & .Net Basics and Branching & Flow Control. OOPs Concepts,...

DeCode Classes | 18/12/2017

0 0
Pro Developer Program Syllabus
What you will learn in Pro-Developer Program: i. Introduction to Web Technologies. ii. Introduction to .Net - Features of .Net, CTS, CLS, CLR and MSIL. iii. C# & .Net Basics - Data Types,...

DeCode Classes | 23/11/2017

1 0

Looking for C# .NET ?

Find best C# .NET in your locality on UrbanPro.

Do you offer C# .NET ?

Create Free Profile »

Find Best C# .NET ?

Find Now »