递归函数

先定义一个函数:

private
    function recursion(x:Real):Real;

实现代码:

implementation
{$R *.dfm}

function TForm1.recursion(x: Real): Real;
begin
  if x=0 then
  begin
    //recursion:=0;//这句和下面那句是一样的效果
    Result:=0;
  end
  else
  begin
    //recursion:=recursion(x-1);//这句和下面那句是一样的效果
    Result:=recursion(x-1);
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  ShowMessage(FloatToStr(recursion(10)));//弹出0
end;
原文地址:https://www.cnblogs.com/168-h/p/15253838.html