Recursive translation of a number from one number system to another
In in some situations in procedures, you can use the word
return
without an argument - that is, in fact, the procedure still does not return anything. This can be useful when recursing, when
return code> is used to end the descent at base cases of parameter values being recursed over. For example, a procedure that converts a number from decimal to binary may look like this:
static void printTwo(int n)
{
if (n == 0) return;
printTwo(n / 2);
if (n % 2 == 0) Console.Write(0);
else Console.Write(1);
}