Loop Control Statements
Loop control statements are used when a section of code may either execute a fixed number of times or while some condition is true.
The While Loop
The while loop is useful to execute a group of statements several times repeatedly depending on condition is True or False. While loop executes a set of statements as long as the test expression is true.
The syntax of While loop
while condition:
statements
In while loop condition is checked first. if the condition is true, then it will execute the statements. After executing the statement, it will go back and check the condition. if the condition is again true, then it will again execute the statements. Python interpreter executes the statements again and this continues until the condition becomes false.
The Flow Chat of while loop
Working of While Loop |
Example: While loop
Output:
0 Comments