What is a program that displays the numbers 1 through 10 using a loop?

 Certainly! Here's a simple example of a Python program that uses a loop to display the numbers 1 through 10:


```python

# Using a for loop

for number in range(1, 11):

    print(number)


# Using a while loop

counter = 1

while counter <= 10:

    print(counter)

    counter += 1

```


In the first example, a `for` loop is used with the `range` function to iterate over the numbers from 1 to 10 (inclusive). In the second example, a `while` loop is employed to achieve the same result, incrementing the counter variable in each iteration until it reaches 10. Both programs will output the numbers 1 through 10.

Auto Refresh and Link Loop

Comments

Popular posts from this blog

What is the primary goal of user interface (UI) design in software development?

Email Scam Alert: The Unexpected Con of Apple Store Card Purchases

What are the key steps involved in the process of website development?