hello how r u guys ?
Q: what is the difference between for loop and foreach loop?
kindly describe deeply
Thanks.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Pradeep ChandrakerRank #941 · 2.2K reputationPosted Jun 24, 2011, 5:43 AM EDT
http://support.microsoft.com/kb/129931/en-us?p=1
http://diditwith.net/2006/10/05/PerformanceOfForeachVsListForEach.aspx
VulpesRank #55 · 29.2K reputationPosted Jun 24, 2011, 6:06 AM EDT
Sandeep ShekhawatRank #2,439 · 577 reputationPosted Jun 24, 2011, 6:10 AM EDT
{
static void Main(string[] gaju)
{
int[] a = { 1, 2, 3 };
//it is for loop
for(int i=0;i
Console.WriteLine(a[i]);
}
Console.WriteLine("----------");
//it is for each loop
foreach(int i in a)
{
Console.WriteLine(i);
}
Console.Read();
}
OutPut:
Bot gives same out put in above code
Vilas GiteRank #951 · 2.1K reputationPosted Jul 1, 2011, 9:35 PM EDT
For Loop: Definition, syntax &used of for loop in various languages
http://en.wikipedia.org/wiki/For_loop
Foreach loop :Definition, syntax &used of foreach loop in various languages
http://en.wikipedia.org/wiki/Foreach_loop
----------------------------------------------------------------------------------------------------
If this reply hepls your post…then "MARK AS ANSWER"!