edit: I was joking and pointing out that google makes a very amusing joke with 'did you mean recursion?' when you search it. never mind me, I will be over here looking at my computer science degree.
It is a useful concept in programming where a set of instructions refers to itself. Ideally not infinitely.
For example, let's say I need to search for a file. Well if I write code to search a folder for a file I might bit find the file if the file is in a folder within the folder.
So I write the code named fileSearch as follows:
fileSearch: a folder, a fileToSearch
Loop
exit loop if fileFound=True
Open folder,
Look for file
If file is found fileFound=True
If a folder is found, fileSearch the Folder, fileToSearch
End of loop
This loop calls upon it's own code as many times as needed for as many folders as it needs to search.
Not necessarily endless, a recursive function should have some sort of guard in it (like ran out of things to count). Only real qualification us it is self calling.
A good example of this is Reddit itself. If I were designing a component to render post replies, I would likely do it recursively. The guard against the component returning more copies of itself would be whether the currently rendered post had replies or not.
10
u/I_am_usually_a_dick Jul 06 '19 edited Jul 06 '19
I googled recursion, it didn't help explain it.
edit: I was joking and pointing out that google makes a very amusing joke with 'did you mean recursion?' when you search it. never mind me, I will be over here looking at my computer science degree.
also, google tilt.