Section Loop.
Variable (A : Type) (f : A -> A) (p : A -> bool).
Fixpoint loop (a : A) (k : nat) {struct k} :=
if p a then Some a else
match k with
| O => None
| S k' => loop (f a) k'
end.

Lemma loop_step k a :
p a = false ->
loop a (S k) = loop (f a) k.