Loops: The while loop statement in Python programming language will repeatedly execute a target statement as long as the given condition is true but the control is transferred out of the loop when condition becomes false.
Syntax:
While expression:
<Statement>
increment
Example:
i = 0
while(i < 9):
print (‘The value is:’, i)
i= i + 1
Example:
primes = [2, 3, 5, 7]
for x in primes:
print(x)
# Prints out the numbers 0,1,2,3,4
for x in range(5):
print(x)
# Prints out 3,4,5
for x in range(3, 6):
print(x)
# Prints out 3,5,7
for x in range(3, 8, 2):
print(x)