user17187571
user17187571

Reputation:

Raise For-Loop Limit

x=4

for i in range(1, x):
    try:
        ...
    except:
        x+=1

The range is

1

2

3

4

And then it stops.

I want the cap to be increased when the exception occurs.

Upvotes: 0

Views: 419

Answers (1)

Tom Karzes
Tom Karzes

Reputation: 24100

If you want the loop limit to change dynamically, then you need to use a while loop:

x = 4
i = 1
while i < x:
    try:
        ...
    except:
        x += 1

Upvotes: 1

Related Questions