whati s wrong with this loop?

procedure TForm1.Button1Click(Sender: TObject);
begin
var j: Integer;
for j:=1 to 5 do
begin
ShowMessage('Box: '+InToStr(j));
end;
end.

i also added one more end; after second last end; but nothing changed. iam new to Delphi and it is frustrating:mad:

i receive the following errors
[Error] Unit1.pas(28): Statement expected but 'VAR' found
[Error] Unit1.pas(29): Declaration expected but 'FOR' found
[Error] Unit1.pas(31): Undeclared identifier: 'InToStr'
[Error] Unit1.pas(32): '.' expected but ';' found
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'

whati s wrong with this loop?

procedure TForm1.Button1Click(Sender: TObject);
begin
var j: Integer;
for j:=1 to 5 do
begin
ShowMessage('Box: '+InToStr(j));
end;
end.

you need to declare the var first:

procedure TForm1.Button1Click(Sender: TObject);
var
  j: integer;
begin
  for j:=1 to 5 do
    begin
      ShowMessage('box : ' + IntToStr(j));
    end;
end;

thanks very much. iam at college currently but i will try that once i get home. thanks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.