I have code like this:
loopcount = 3
for i in range(1, loopcount)
somestring = \'7\'
newcount = int(somestring)
loopcount = newcount
The range is created based on the value of loopcount
at the time it is called--anything that happens to loopcount afterwards is irrelevant. What you probably want is a while statement:
loopcount = 3
i = 1
while i < loopcount:
somestring = '7'
loopcount = int(somestring)
i += 1
The while
tests that the condition i < loopcount
is true, and if true, if runs the statements that it contains. In this case, on each pass through the loop, i is increased by 1. Since loopcount is set to 7 on the first time through, the loop will run six times, for i = 1,2,3,4,5 and 6.
Once the condition is false, when i = 7
, the while loop ceases to run.
(I don't know what your actual use case is, but you may not need to assign newcount, so I removed that).
You can't increase the number of iterations once the range has been set, but you can break out early, thereby decreasing the number of iterations:
for i in xrange(1, 7):
if i == 2:
break