Syntax of while loop

initialization: An initial value is assigned to a variable in this section.
condition: Condition is checked and statements are executed inside while loop if condition is true.
increment or decrements:  Update initial value to count number of iteration and based on the update value condition will be false and loop will stop.



Iteration 1
Iteration 2
Iteration 3
Iteration 4

If you don’t understand how this while loop works then read for loop first.

Next Previous