https://msdn.microsoft.com/en-us/library/e4213hs1.aspx Here is the documentation for the operator.
b==0
is the conditional
a
will be returned if
b == 0
gcd(b, a % b)
will be returned if
b != 0
This recursive solution will return the greatest common divisor of the two original numbers by continually looking until the GCD is found.
Consider two numbers 50, 45
when you originally call the function:
answer = gcd(50, 45)
the function will show that b != 0, therefore instead of return the value of A, will return a recursive call to itself with the parameters gcd(45, 50%45)
50%45==5 so B will now equal 5 in this recursive call:
now when B != 0, the call will happen again for a third time, this time with gcd(5, 45%5)
45%5==0 so B will now equal 0
since this third call to the function will have B==0, the current value of A (which is 5), will be returned, rather than another recursive call. This value will be returned all the way back up to the first call, which will return it to whatever called it originally.
Some numbers have no common divisors greater than 1. Try something like 50,47 and see how it will return the value of 1!