Python 3 While loop. | pycoder
Python3 While Loop.
In while loop, test expression is checked first. The body of the loop is entered only if the test_expression evaluates to True. After one iteration, the test expression is checked again. This process continues until the test_expression evaluates to false.
In python, the body of the while loop is determined through indentation.
Body starts with indentation and the first unintended line marks the end.
Python interprets any non-zero value as True. None and 0 are interpreted as False.
Example:
x = 0
while True:
print (x)
Output:
>> 0
0
0
0
0
Exit in loop click ctrl + c
Any problem pleas watch video
Loops are used in programming to repeat a specific block of code. In this article, you will learn to create a while loop in python.
The while loop in python is used to iterate over a block of code as long as the test expression (condition) is true.
We generally use this loop when we don't know beforehand, the number of time to iterate.
Syntax
while test_expression:
Body of while
In while loop, test expression is checked first. The body of the loop is entered only if the test_expression evaluates to True. After one iteration, the test expression is checked again. This process continues until the test_expression evaluates to false.
In python, the body of the while loop is determined through indentation.
Body starts with indentation and the first unintended line marks the end.
Python interprets any non-zero value as True. None and 0 are interpreted as False.
Example:
x = 0
while True:
print (x)
Output:
>> 0
0
0
0
0
Exit in loop click ctrl + c
Any problem pleas watch video
No comments: