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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
SenthilkumarPosted Apr 4, 2012, 12:37 AM
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.
FireMystPosted May 20, 2016, 2:31 AM
http://cc.davelozinski.com/c-sharp/for-vs-foreach-vs-while
Saroj Kumar SahuPosted Apr 4, 2012, 1:27 AM
difference.
While: Keep going until this condition is met.
For: Keep going for X number of iterations.
qwertyPosted Apr 4, 2012, 12:41 AM