The While Loop

In most computer programming languages, a while loop is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition. The while loop can be thought of as a repeating if statement.

In this program, there is a condition testCondition in while loop. At first, Compiler checks this test condition.

There are 2 conditions
  • Test condition succeeds i.e. test condition is true. If it is so, code inside the while block is executed. Then, again test condition is tested. Then, the process is repeated until test condition fails.
  • Test condition fails i.e. test condition is false. If it is so, while loop is terminated. Code after the while block starts executing.

Check out this example.

 
0
1
2
3
4
5

The while loop will increase the x until it is less or equal to 5. If the x is bigger then 5, the while loop will be terminated. 

 


 

Follow and like us:
Click to rate this post!
[Total: 0 Average: 0]

Leave a Reply

Your email address will not be published. Required fields are marked *