Python Basics: How to Count from 1 to 10 Using a while Loop

# This program demonstrates a 'while' loop by displaying numbers from 1 to 10.
counter = 1 # Initialize a variable named 'counter' and set its starting value to 1.

while counter <= 10: # Start a loop that runs as long as 'counter' is less than or equal to 10.
    print(counter) # Print the current value of 'counter' to the console.
    counter += 1 # Increment the 'counter' by 1 so the loop progresses and eventually ends.

Comments