0

Question is about for loops and range

In for loops if we give command For i in range(1,-10,2) and print i These shows no output .why

5th Sep 2025, 2:01 PM
Poorvik AS
Poorvik AS - avatar
3 Answers
0
This is because you are using a descending loop. The first number in the range should be less than the second number. But you have 1 greater than -10.2. To display the numbers in descending order, use slices.
5th Sep 2025, 2:13 PM
Mila
Mila - avatar
0
Poorvik AS In addition to Mila suggestion, you can also use negative step value to run the loop in reverse order. For example: for i in range(1, -10, -1): print(i)
5th Sep 2025, 3:02 PM
Gulshan Mahawar
Gulshan Mahawar - avatar