We then use the concept of a function to code each task. A function then is a mini-program in its own right. It has its own variables, its own name, it performs its own calculations and returns results. Statements are executed one by one. When the system comes across a call to a function, control switches to the statements in the function until all the statements in the function are done.
Control then resumes at the point where the function was called.
What we want to learn is how we might go about designing a function of our own and use it in a program. At this point it is important to distinguish between two scenarios where functions might be used. In some cases, a function will execute a set of commands based on given data and return a single result . In other cases, the function has to modify several things . To make matters a little more concrete, let's devise a function which, given a value for x , returns the value of x 5 e - x .