Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
38
Task/Nested-function/Free-Pascal/nested-function.pas
Normal file
38
Task/Nested-function/Free-Pascal/nested-function.pas
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
// In Pascal, functions always _have_ to return _some_ value,
|
||||
// but the the task doesn’t specify what to return.
|
||||
// Hence makeList and makeItem became procedures.
|
||||
procedure makeList(const separator: string);
|
||||
// The var-section for variables that ought to be accessible
|
||||
// in the routine’s body as well as the /nested/ routines
|
||||
// has to appear /before/ the nested routines’ definitions.
|
||||
var
|
||||
counter: 1..high(integer);
|
||||
|
||||
procedure makeItem;
|
||||
begin
|
||||
write(counter, separator);
|
||||
case counter of
|
||||
1:
|
||||
begin
|
||||
write('first');
|
||||
end;
|
||||
2:
|
||||
begin
|
||||
write('second');
|
||||
end;
|
||||
3:
|
||||
begin
|
||||
write('third');
|
||||
end;
|
||||
end;
|
||||
writeLn();
|
||||
counter := counter + 1;
|
||||
end;
|
||||
// You can insert another var-section here, but variables declared
|
||||
// in this block would _not_ be accessible in the /nested/ routine.
|
||||
begin
|
||||
counter := 1;
|
||||
makeItem;
|
||||
makeItem;
|
||||
makeItem;
|
||||
end;
|
||||
Loading…
Add table
Add a link
Reference in a new issue