The biggest problem with dividing a large program into multiple subprograms is to make each subprogram as independent, or loosely coupled, as possible. That means if one subprogram fails, it doesn’t wreck the entire program along with it, like yanking out a single playing card from a house of cards. One major advantage of subprograms is that you can isolate common program features in a subprogram that you can copy and reuse in another program.

 

For example, suppose you wrote a word processor. Although you could write it as one massive, interconnected tangle of code, a better approach might be dividing the program functions into separate parts. By doing this, you could create a separate subprogram. Inside the function, one or more commands must calculate a new result. Then you use the RETURN keyword to define what value to store in the function name.

 

Whatever value this is, it must be the same data type that you defined for the function name in the first line. So if you defined a function as a String data type, you can’t return an integer value from that function. After listing a parameter list, the first line also defines the data type that the function name can hold, such as an integer, a string, or a single decimal number.