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:

    “Possibly the Creator did not make the world chiefly for the purpose of providing studies for gifted novelists; but if he had done so, we can scarcely imagine that He could have offered anything much better in the way of material ...”
    —Elizabeth Stuart Phelps (1844–1911)

    “Thus one can observe that those who proclaim piety as their goal and purpose usually turn into hypocrites.”
    —Johann Wolfgang Von Goethe (1749–1832)

    “We need not only a purpose in life to give meaning to our existence but also something to give meaning to our suffering. We need as much something to suffer for as something to live for.”
    —Eric Hoffer (1902–1983)