-1
would like to know how I can create a trigger to rotate a function only when a specific variable changes value within a loop, only without needing to define a variable outside that loop, for example:
a = 0
a_anterior = 0
for i in range(20):
if i == 5 or i == 9:
a += 1
if a != a_anterior:
print('a trocou de valor em i =', i)
a_anterior = a
in this case I needed to define an auxiliary variable (a_previous), but the program I am doing requires that I do it several times, so I keep declaring too auxiliary variable, I would like to know how to do this process without having to declare anything, I thank you in advance.
In your case, you can already put the function inside the
if
, even because the variablea
, only exchange value if theif
is true, so you already have a trigger for a function.– FourZeroFive
But would it be possible to do without being inside the if? because in the real case the values would be updated by other different functions, there is no way I do it
– Rafael
Maybe a global helper variable will help you, every time some value changes this variable
– FourZeroFive