Demonstration on For Loop Using Range Keyword

Demonstration on For Loop Using Range Keyword


For Loop Using Range To Display First 10 Numbers

for i in range(1,10,1):

    print(i)

Output:

1

2

3

4

5

6

7

8

9

In this program loop will start by 1 because in the range function 1 is given as start value. Stop value is 10. So loop execution will stop when 10 get. The step value is 1 so in each iteration loop will be incremented by 1.

By default the default start value is 0 and and default step value is 1.

Without Using step Value


print("Without giving step value:")

for i in range(0,10):

    print(i)

Output:

Without giving step value:

0

1

2

3

4

5

6

7

8

9


Without Using Start Value

print("Without giving step value:")

for i in range(2,10):

    print(i)

Output:

Without giving step value:

2

3

4

5

6

7

8

9


By Using Stop Value


print("By using only stop value:")

for i in range(10):

    print(i)


Output:

By using only stop value:

0

1

2

3

4

5

6

7

8

9

टिप्पणी पोस्ट करा

0 टिप्पण्या