A subprogram essentially yanks out two or more commands from your main program and stores them in another part of your main program or in a separate file. The reasons for isolating commands in a subprogram and out of your main program.
If you wanted to write a horse race prediction program, you wouldn’t have to write the whole thing from scratch. You could copy the subprograms from another program and reuse them in your new project. By reusing subprograms, you can create more complicated programs faster than before. After programmers create enough useful subprograms, they can store these subprograms in a “library” that they and other programmers can use in the future.
Unlike a subprogram that may or may not return a modified value, functions always return a value. To call a function, you must assign the function name to a variable or use the function name itself as a variable. When this subprogram runs, it calls itself, essentially making a second copy of itself, which then makes a third copy of itself, and so on. A common problem used to demonstrate recursion is calculating a factorial which multiples a number by a gradually decreasing series of numbers.