For Loop Example Programs


Range(Stop)

This code is written in the Python programming language and defines a for loop that iterates ten times. The loop prints the value of i on each iteration.

The range(10) function generates a sequence of numbers from 0 to 9, and the for loop iterates over this sequence. On each iteration, the value of i is updated to the next number in the sequence, and the code inside the loop (print(i)) is executed. As a result, the numbers 0 to 9 are printed, one number per line.

Source Code

for i in range(10):
print(i)
To download raw file Click Here

Output

0
1
2
3
4
5
6
7
8
9

Range(Start,Stop)

This code is written in the Python programming language and defines a for loop that iterates ten times. The loop prints the value of i on each iteration.

The range(1, 10) function generates a sequence of numbers from 1 to 9, and the for loop iterates over this sequence. On each iteration, the value of i is updated to the next number in the sequence, and the code inside the loop (print(i)) is executed. As a result, the numbers 1 to 9 are printed, one number per line.

Source Code

for i in range(1,10):
   print(i)
To download raw file Click Here

Output

1
2
3
4
5
6
7
8
9

Range(Start,Stop,Step)

This code is written in the Python programming language and defines a for loop that iterates five times. The loop prints the value of i on each iteration.

The range(1, 10, 2) function generates a sequence of numbers from 1 to 9 with a step size of 2. The for loop iterates over this sequence. On each iteration, the value of i is updated to the next number in the sequence, and the code inside the loop (print(i)) is executed. As a result, the numbers 1, 3, 5, 7, and 9 are printed, one number per line.

Source Code

for i in range(1,10,2):
   print(i)
To download raw file Click Here

Output

1
3
5
7
9