Python uses while loop to print 1 to 10
We will use Python'swhileloop to print numbers from 1 to 10.whileThe loop will continue to execute until the given condition is no longer satisfied.
Example
i = 1
while i <= 10:
print(i)
i += 1
while i <= 10:
print(i)
i += 1
Code analysis:
i = 1Initialize variableiand set its value to 1.while i <= 10:This is awhileloop; as long asithe value is less than or equal to 10, the loop will continue to execute.print(i)In each loop, print the currentivalue.i += 1After each loop ends, increase theivalue by 1.
Output result:
1 2 3 4 5 6 7 8 9 10Other extensions
Python3 Examples