While loop :
- Firstly we have to declare a variable outside the while loop.
- Then type a keyword while.
- Write the stopping condition or test condition inside the parentheses.
- Code block inside the curly braces.
- Then write the increment or decrement inside the curly braces.
When we will use the while loop and for loop?
When we know how many times the loop should run, the for loop is ideal. If we don’t know how many times the loop should run, then the while loop is perfect.
Post a Comment