RosettaCodeData/Task/Nested-function/Free-Pascal-Lazarus/nested-function.pas

39 lines
879 B
ObjectPascal
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
// In Pascal, functions always _have_ to return _some_ value,
// but the the task doesnt 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 routines 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;