The above can be coded not to useremove athe variableextra modulo; however, it either requires twoa modulusvariable operationsdeclaration perfor non-baseeach case,level of recursion or an extra recursive call (the base case would be if y = 0, meaning if x mod y = 0 we would make one more call wehereas here we simply return). All three implementations are valid, only depending on what is moremost efficient for the language and processor (in C++, modulo is an inline operation, but other languages require a Mod(x,y) function call).
Below is the same algorithm using an iterative approach:
Line 67 ⟶ 66:
}
The iterative algorithm requires threea assignmenttemporary statements per iterationvariable, and even given knowledge of the Euclidean Algorithm it is more difficult to understand the process by simple inspection. They are though, in fact, very similar in their steps.