Visibility of Nested Functions
Every function has a certain scope, that is, a set of other functions to which it is visible. A nested
function is available:
• From the level immediately above it. (In the following code, function A can call B or D, but not C or
E.)
• From a function nested at the same level within the same parent function. (Function B can call D,
and D can call B.)
• From a function at any lower level. (Function C can call B or D, but not E.)
function A(x, y)
% Main function
B(x,y)
D(y)
function B(x,y)
% Nested in A
C(x)
D(y)
function C(x)
% Nested in B
D(x)
end
end
function D(x)
% Nested in A
E(x)
Nested Functions
20-31
Précédent

- 739/1450

Suivant