I don't know how you can do that using a for/while loop but I think timers should work.
In the player script,
timer = null
health = 1000
func health_decrement():
health -= 50 # Amount to decrement from health in 0.25 secs
func _ready():
timer = Timer.new()
timer.set_one_shot(false)
timer.set_wait_time(0.25) # 0.25 is just an example.
timer.connect("timeout", self, "health_decrement")
add_child(timer)
In the area2d script,
timer = get_node("player/timer")
func on_area_body_enter(body):
timer.start()
func on_area_body_exit(body):
timer.stop()
This should work!