You're passing option_current
which is defined to be 1 and everytime you call your function you're just printing option_current += 1
which is 2. It's not updating the way you think it is. They're in different namespaces. option_current = option_current + 1
is within the namespace of that function whereas option_current
outside of it is global. So, your print statement inside of that function and the increment is just continuously printing and +1 ing the "local" option_current
within that function and not modifying the global variable. If that makes sense.
Using global
which I don't recommend.
option_current = 1
def myfunction():
global option_current
option_current = option_current + 1
print ( option_current )
while ( option_current < 10 ):
myfunction()
One way without global
def myfunction(current):
current += 1
print(current)
return current
current = 1
while ( current < 10 ):
current = myfunction(current)
Although, if this is all your function does....
current = 1
while current < 10:
print(current)
current += 1