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:
“...Often the accurate answer to a usage question begins, It depends. And what it depends on most often is where you are, who you are, who your listeners or readers are, and what your purpose in speaking or writing is.”
—Kenneth G. Wilson (b. 1923)
“A major misunderstanding of child rearing has been the idea that meeting a childs needs is an end in itself, for the purpose of the childs mental health. Mothers have not understood that this is but one step in social development, the goal of which is to help a child begin to consider others. As a result, they often have not considered their children but have instead allowed their childrens reality to take precedence, out of a fear of damaging them emotionally.”
—Elaine Heffner (20th century)
“The moment a mere numerical superiority by either states or voters in this country proceeds to ignore the needs and desires of the minority, and for their own selfish purpose or advancement, hamper or oppress that minority, or debar them in any way from equal privileges and equal rightsthat moment will mark the failure of our constitutional system.”
—Franklin D. Roosevelt (18821945)