0

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'

2
Contributors
2
Replies
3
Views
11 Years
Discussion Span
Last Post by nsan
0

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;
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.