13.3 Calculate a GCD in LOGO programming

A little recursive procedure will calculate the GCD of two integers :a and :b

to gcd :a :b  
if (modulo :a :b)=0 [output :b][output gcd :b modulo :a :b]  
end  
 
print gcd 2160 888  
24

Note: It’s important to put parenthesis around modulo :a :b. Otherwise, the interpreter would try to evaluate :b = 0. If you don’t want to use parenthesis, write: if 0=remainder :a :b