In the above syntax, the test expression inside parenthesis is a boolean expression. If the test expression is evaluated to true,
This process goes on until the test expression is evaluated to false. If the test expression is evaluated to false, the while loop is terminated.
Output
In the above example, we have a test expression (i <= 10). It checks whether the value of i is less than or equal to 10.
Here initially, the value of i is 1. So the test expression evaluates to true for the first time. Hence, the print statement inside while loop is executed. Inside while loop notice the statement ++i; This statement increases the value of i by 1 in each iteration. After 10 iterations, the value of i will be 11. Then, the test expression (i <= 10)(i <= 10) evaluates to false and while loop terminates. The following code block executes sum of natural numbers from 1 to 100.
The output for the above program will be Sum = 5050. Here, we have two variables named sum and i whose initial values are 0 and 100 respectively. In each iteration of the while loop,