What is the difference between the While and For loop? Provide a .NET syntax for both loops. | Eklavya Online

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:

  1. While loop:
  2. while(condtion) {
  3. //statements to excute.
  4. }
  5. For loop:
  6. for(intialization; condition; Increment or decrement)
  7. {
  8. // statements to be excuted.
  9. }