I agree with @cybereality and @duane that you shouldn't be messing with yield/await if you're a beginner, and instead approach it in the way @DaveTheCoder suggested. That being said, making a coroutine that calls your function periodically may be an elegant way to do it because you see an explicit loop in your code, which is neat:
func call_consecutive(method: Callable, delay: float, number_of_calls: int) -> void:
while number_of_calls:
method.call()
await get_tree().create_timer(delay).timeout
number_of_calls -= 1
func _ready():
var move_to_next_position = func():
print("MOVING TO NEXT POSITION")
call_deferred( "call_consecutive", move_to_next_position, .5, 10 )
It could be particularly useful if you want to do something in irregular intervals, or need to check for some conditions in-between the calls:
var some_condition = false
func call_consecutive(method: Callable, delays: Array) -> void:
for delay in [0] + delays:
await get_tree().create_timer(delay).timeout
method.call()
if some_condition:
break
func _ready():
var do_the_thing = func():
print("DOING THE THING")
call_deferred( "call_consecutive", do_the_thing, [.5, 1.0, .3])