Google News
logo
.Net - Interview Questions
What is the difference between the While and For loop? Provide a .NET syntax for both loops.
The For loop provides a concise way of writing the loop structure, but the While loop is a control flow statement that allows repetitive execution of the code. Initialization, condition checking, iteration statements are written at the top of the For loop, but only initialization and condition checking is done at the top of the while loop.
 
Syntax :
 
While loop :
while(condtion) {

//statements to excute.

}
 
For loop :
for(intialization; condition; Increment or decrement){

// statements to be excuted.

}
Advertisement