Nested Function - Purpose

Purpose

Nested functions are a form of information hiding and are useful for dividing procedural tasks into sub tasks which are only meaningful locally; it avoids cluttering other parts of the program with functions, variables, etc. unrelated to those parts. Nested functions therefore complement other structuring possibilities such as records and objects.

In languages with nested functions, functions may normally also contain local constants, and types (in addition to local variables, parameters, and functions), encapsulated and hidden in the same nested manner. This may further enhance the code structuring possibilities.

Nested functions can also be used to terminate a nested for loop early.

Read more about this topic:  Nested Function

Famous quotes containing the word purpose:

    Natural selection, the blind, unconscious, automatic process which Darwin discovered, and which we now know is the explanation for the existence and apparently purposeful form of all life, has no purpose in mind. It has no mind and no mind’s eye. It does not plan for the future. It has no vision, no foresight, no sight at all. If it can be said to play the role of the watchmaker in nature, it is the blind watchmaker.
    Richard Dawkins (b. 1941)

    Rule of religion: purpose breathes even in dirt and stones.
    Mason Cooley (b. 1927)

    The purpose of punishment is to improve those who do the punishing—that is the final recourse of those who support punishment.
    Friedrich Nietzsche (1844–1900)