Call a function in a tag

I have a function defined in project library. I called the function when the tag changes.
what i want is that this function be run 5 times when the tag changes. i have to try with the loops but it’s not working
x = 1
while x < 5:
script.myfunction()
x = x +1