Recursion is the process of a function calling itself from within its own code. You can think of it as another way to accomplish a looping construct. A recursive function just keeps calling itself until it has completed the problem at hand. That brings up a good point, and that is to make sure that your recursive function actually terminates and returns at some point. Otherwise, the recursive function will run forever, exhaust your memory, and crash your computer. Having a step where the function actually finishes is known as a breaking condition.
15-105 SPRING 2009 [CORTINA]
Print name N times using recursion
Join Stack Overflow to learn, share knowledge, and build your career. Connect and share knowledge within a single location that is structured and easy to search. Ok so I'm writing a program that will run through a grid, and find chambers. For each chamber that is white it fills it with a color. As long as the white space next to this spot is also white it continues to fill with color until the space is walled off. Then it continues its scan till it finds a new chamber of white.
Subscribe to RSS
Join Stack Overflow to learn, share knowledge, and build your career. Connect and share knowledge within a single location that is structured and easy to search. I have a homework question that asks to make a recursive function to generate a square with side length n made of asterisks.
One of the most fundamental tools in programming is a loop. While there are many different types of loops, almost each type of loop has the same basic function: iterating over data to analyze or manipulate it. Recursion is another popular type of function and although it can also analyze and manipulate sequences of data similar to a loop, recursion is probably less understood in many cases, and can often be somewhat confusing. Almost all recursive functions can be re-written as loops, and vice versa.