While Loops

Why should we care about while loops ?

Because it allows us to be more lazy , and allows us to execute a block of code , multiple times but only write it one time.

Let’s make one , and learn how to love the art of the while loops

For now let’s just make a counter integer variable.

To make a while loop, we only need to write while and type 2 parenthesis.

The parenthesis will allows us to test a condition of our choosing.

For now let’s tell our program that we want to increase our counter as long as its less than 10.

Output :

Wow , we didn’t have to write 10 numbers , or even worst 10 system outs to get 10 numbers to be display as our output !!

How beautiful are the while loops. Play around with your condition , and master this useful technique that makes our life easier.

Leave a comment