For help with repeats, I like to refer people to the first post in this thread, which contains several examples:
The topic at hand here is notifications, but that doesn't really matter (that is just the contents of the repeat); the crux of the issue is how to stop repeats when a condition is met, which these examples demonstrate.