While Loop Flowchart In Python
Last updated June 6, 2023 by Jarvis Silva
Today in this tutorial I will show you how to create a while loop flowchart in python. a flowchart in programming is a picture diagram which is used to represent an algorithm or a process.
Python While Loop Flowchart Diagram
As you can see the first box in the flowchart inside that it is written is condition true if the condition is false then as you can see the line arrow going to exit while loop which means the while loop will end.
If the condition is true then it will execute the code which is there inside the loop, then after executing all the code it will go back to the first step and check if the condition is still true so this way the while loop runs until the condition is true and ends when the condition becomes false.
If you don’t make the condition false inside the while loop then the while loop will run infinitely so you need to make false after some conditions.
While Loop Syntax In Python
while condition:
body # it will be executed if the condition is true
The above is the syntax for creating a while loop in python, you need to write your condition where I have written condition and if the condition is true the code inside the body will run.
i = 1
while i < 10:
print(i)
i = i + 1
Above is the code example of a simple while loop program in python as you can see we have set a variable i = 1 and the condition for while is i < 10 this means while i is less than 10 run the loop.
i is 1 which is less than 10 which makes the condition true so it will run the code inside the body which is printing the value of i which is 1 for now after that it increases the value of i by 1 each time the loop runs.
After the value of i becomes 9 which is still less than 10 then it will increase i by 1 which will make it 10 then it will check the condition and it will become false because i is not less than 10 now but it is equal.
You can run the above code on your computer or you can use an online python compiler and you will see the below output as you can see the while loop runs for 9 times.
1
2
3
4
5
6
7
8
9
So this was everything about while loops and flowchart in python, Want more tutorials like this, then you need to join our Telegram channel to get our blog updates. Here are more python guides you may find helpful:
I hope you understood about while loops in python and how they work. They work the same in other programming languages, only the syntax is different.
Thanks for reading, have a nice day 🙂