helper that calls a predicate function until true