unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    CalculateButton: TButton;
    EndEdit: TEdit;
    Label1: TLabel;
    ResultEdit: TEdit;
    Label2: TLabel;
    procedure CalculateButtonClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.CalculateButtonClick(Sender: TObject);
var
  index:Integer;
  sum:Integer;
  EndCount:Integer;
begin
 Sum:=0;
 index:=0;

 EndCount:=StrToInt(EndEdit.Text);

 while index<EndCount do
  begin
   Sum:=Sum+index;
   index:=index+1;
  end; 

 ResultEdit.Text:=IntToStr(Sum);
end;

end.
