let us say.
a = 1
b = 10
for i in range(a, b):
print(i)
if i == 5:
a +=1 # and run loop again.
How would I increase a by 1 and run the loop again?
Is there any way?
let us say.
a = 1
b = 10
for i in range(a, b):
print(i)
if i == 5:
a +=1 # and run loop again.
How would I increase a by 1 and run the loop again?
Is there any way?
You could use two loops, but think twice about what you want to achieve, as I don’t think any of this will do what you want.
Here’s something to think about:
>>> a=range(1,6)
>>> a
[1, 2, 3, 4, 5]
>>> for i in a:
... print a[i-1:]
...
[1, 2, 3, 4, 5]
[2, 3, 4, 5]
[3, 4, 5]
[4, 5]
[5]
I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>
) will also add backticks around text.