In the last session, we discussed loop statements and various methods. Now, we will learn the importance of the while statement.
Let’s start,
WHILE STATEMENT
- We can run the statement when the condition is true, false means exit.
- While statement plays a very important role in projects.
Syntax
![]()
Flow chart
![]()
A simple example of a while statement
Printing the given values mentioned times
Numbers in descending order consequently
Ascending order with 2 jumps ( odd )
Ascending order with 2 jumps ( even )
Multiples of 3 using while loop
Multiples of 3 with 2 jumps
Printing ( i x 3 ) values using loop
Number divisible by 2 and 3 using while and nested if
Number divisible by 2 and 3 using while, if, and logical operator
Sum of first n consecutive numbers
While else using loop condition
Printing a word using index
Game using a while loop statement
I hope now you can understand about While Loop. If you have any query please ask me. We'll see a more interesting topic in the future.