Question: freeze when finding the GCD(greatest common divisors) of two integers

the question is as follow:

1)receive two integers p and q

2)declare two local p1 and q1 and give them intial values and q

3)check if p o q are equal or less to zero print works only with positive integers

4)while p1 not equal to q1 then p1-a1 otherwise q1-p1

5)whenever p1=q1 we have the GCD

note:must use procedure and call it for different values of p and q after the procedure is written

-by following the instruction above this is what i got

GCD:=proc(p,q)

local p1,q1;

p1:=p;

q1:=q;

if p<=0 OR Q<=0 then 'works only with positive integers'
else while p1<>q1 do if q1<p1 then p1-q1 else q1-p1

end if;

end do;

end if;

end proc;

but when I call two integers eg:p=2, q=6 -> GCD(2,6) maple just freeze...evaluating....forever. is it because i got the procedure wrong etc? it would be helpful if anyone can help me with this. thanks

 

 

Please Wait...