Question: Maple procedure for the first return map?

Hi everyone! Please help me..

I want to do the procedure for the FirstReturn of a map. I think my procedure is not correct.
I want to write a procedure 
FirstReturn:=proc(F,x,p,q) where F is any map (function), x is the integer and the starting point, and p&q is the integer that form an interval [p,q].
If i start from the point x in [p,q], then after some iterations, there is Ft(x) in the interval [p,q].
I am interested with the the value of Ft(x) and the iteration, t when it comes back to the interval [p,q]  to be the output of the procedure.
What i did is shown below. But I dont have any idea to make it work!

Please help. Really appreciate your help.. 

FirstReturn := proc (F, x, p, q)
local t, z;
if p <= x and x <= q then F(x) := x end if;
for t while x < p and q < x or t = 1 do
x := z;
if p <= z and z <= q then
z;
end if;
end do;
return (z, t);
end proc;


Please Wait...