Recursion to cycle