Hi friends,
I want to know that what's the difference between for loop and while loop? What are the task which can do with for not with while please explain in programming scenario?
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
SenthilkumarRank #387 · 6.5K reputationPosted Apr 3, 2012, 8:37 PM EDT
The for and while loop statement is used to iterate.
A while loop is very much similar to a for loop except that initialization, checking the boolean condition and incrementing the counter value is done at different steps as shown in the below example, otherwise while loop is same as the for loop.
The for loop has three parts.
Initialization
Condition
Increment/Decrement
for(int i=0;i<10;i++)
{
Console.WriteLine(i.toString());
}
While Loop:
int i =0;
while(i<10)
{
i = i+1;
}
Both can do the infinite loop:
for(;;)
{
}
while(true)
{
}
Differences:
While is an entry controlled loop. It is good for the boolean expression checking.
Mostly both has the common features.
qwerty10 reputationPosted Apr 3, 2012, 8:41 PM EDT
Saroj Kumar SahuRank #1,765 · 849 reputationPosted Apr 3, 2012, 9:27 PM EDT
difference.
While: Keep going until this condition is met.
For: Keep going for X number of iterations.
FireMyst20 reputationPosted May 19, 2016, 10:31 PM EDT
http://cc.davelozinski.com/c-sharp/for-vs-foreach-vs-while