recursion code example

Example 1: recursion

# modified code tranclated to python from (Drab Duck)

def fact(num):
  if num <= 1:
      return 1
  else:
    return num*fact(num-1)

Example 2: recursion

int function(int value) {
   if(value < 1)
      return;
   function(value - 1);

   printf("%d ",value);   
}

Example 3: recursion

/*Java*/
static void recursion(){ recursion(0); }
static void recursion(int x){
	System.out.println("eheh " + x);
    if(x != 666) recursion(x+1);
}

Example 4: recursion

Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion
Did you mean: recursion

Example 5: recursion

def recursive_function(parameters):
    if base_case_condition(parameters):
        return base_case_value
    recursive_function(modified_parameters)

Example 6: recursion

int function1(int value1) {
   if(value1 < 1)
      return;
   function2(value1 - 1);
   printf("%d ",value1);   
}
int function2(int value2) {
   function1(value2);
}

Example 7: recursion

Click the Did you mean

Example 8: recursion

function loop(x) {
  if (x >= 10) // "x >= 10" is the exit condition (equivalent to "!(x < 10)")
    return;
  // do stuff
  loop(x + 1); // the recursive call
}
loop(0);

Example 9: recursion

def foo():
	foo()

Example 10: Recursion

/**
 * Return all subsequences of word (as defined above) separated by commas,
 * with partialSubsequence prepended to each one.
 */
private static String subsequencesAfter(String partialSubsequence, String word) {
    if (word.isEmpty()) {
        // base case
        return partialSubsequence;
    } else {
        // recursive step
        return subsequencesAfter(partialSubsequence, word.substring(1))
             + ","
             + subsequencesAfter(partialSubsequence + word.charAt(0), word.substring(1));
    }
}