Home > other >  Raise For-Loop Limit
Raise For-Loop Limit

Time:10-21

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.

CodePudding user response:

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
  • Related