While Loop is used to execute task multiple times until the specified condition is true
In place of Condition, you will write the condition until the task should be executed
Now, Lets see some Examples :
Print "Hello World" 20 times.
We have declared a variable i=1
Next, We have used a while statement with a condition i<=10 Thatmeans, until and unless the value of i becomes 10 the console.log("Hello world"); and i++ will be executed.
We have used i++ to increment the value of i by 1 i.e. i=i+1
We will make a program that gives sum of first 10 natural numbers.
We have declared variables sum=0 , number=0 and i=1 then we have used while loop to iterate i until its values becomes equal to numbers Every time value of i will Add to the Value of sum
Then, Value of sum is printed to the Console Tab.