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 core competence of human beings that sets them apart from AI?

Keeping Up: Today's Most Advanced AI Models Intro

What are the artificial intelligence examples in real life?