Skip to content

Print first 10 natural numbers using while loop in Python | Example Code

  • by

To print the first 10 natural numbers using the while loop can do by repeating a block of code until a specific condition is met. While the loop does iteration until a specified condition is true.

Print first 10 natural numbers using while loop in Python

Simple example code runs the loop until “i” is greater or equal to 10. Increase the “i” value on every iteration.

i = 1
while i <= 10:
    print(i)
    i += 1

Output:

Print first 10 natural numbers using while loop in Python

Use end in print to print in single line output

i = 1
while i <= 10:
    print(i, end='  ')
    i += 1

Output: 1 2 3 4 5 6 7 8 9 10

Do comment if you have any doubts or suggestions on this Python print with the while loop topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.