Mohammad AmanRank #4,571 · 337 reputationPosted Nov 3, 2015, 10:10 PM EST
+1
a for loop is a construct that says "perform this operation n. times". a foreach loop is a construct that says "perform this operation against each value/object in this IEnumerable"
MahaRank #2,573 · 543 reputationPosted Nov 4, 2015, 12:40 PM EST
0
http://www.dotnetperls.com/foreach
Foreach. A program iterates over a collection. The index of each element is not needed. Only the elements are needed. With foreach we access just the elements.
http://www.dotnetperls.com/for
For-loops. Often we loop through numbers. These can be used as indexes of an array, or just for a numeric algorithm. For-loops are ideal here.
Rajeesh MenothRank #118 · 18.4K reputationPosted Nov 3, 2015, 11:03 PM EST
Mohammad AmanRank #4,571 · 337 reputationPosted Nov 3, 2015, 10:10 PM EST
Ravi KumarRank #2,085 · 690 reputationPosted Nov 3, 2015, 10:07 PM EST
MahaRank #2,573 · 543 reputationPosted Nov 4, 2015, 12:40 PM EST
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts