用这么麻烦吗?递归不就完了 procedure RecursionForeachAllFiles(AMemo :TMemo; AFilePath :String); var _SearchRec :TSearchRec; _Finded :Integer; begin if AFilePath[Length(AFilePath)] <> '\' then AFilePath := AFilePath + '\'; _Finded := FindFirst(AFilePath + '*.*', faAnyFile, _SearchRec); while _Finded = 0 do begin if (_SearchRec.Attr and faDirectory) <> 0 then begin if (_SearchRec.Name <> '.') and (_SearchRec.Name <> '..') then RecursionForeachAllFiles(AMemo, AFilePath +_SearchRec.Name); end else begin AMemo.Lines.Add(AFilePath + ':' + _SearchRec.Name); end; _Finded := FindNext(_SearchRec); end; FindClose(_SearchRec); end;
var IsBreak :boolean; begin …… IsBreak := False; repeat …… while ex1 do begin …… if Ex2 then begin IsBreak := True; break; end; …… end; if IsBreak then break; until ex3 …… end;
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Edit1: TEdit; Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject); var odds,sum:integer; begin sum:=0; odds:=1; while odds<= strtoint(Edit1.Text) do begin sum:=sum+odds; odds:=odds+2; end; Showmessage(inttostr(sum)); end;procedure TForm1.Button2Click(Sender: TObject); var odds,sum:integer; begin sum:=0; odds:=1; Repeat sum:=sum+odds; odds:=odds+2; until odds > strtoint(Edit1.Text); Showmessage(inttostr(sum)); end;end.
procedure RecursionForeachAllFiles(AMemo :TMemo; AFilePath :String);
var
_SearchRec :TSearchRec;
_Finded :Integer;
begin
if AFilePath[Length(AFilePath)] <> '\' then
AFilePath := AFilePath + '\';
_Finded := FindFirst(AFilePath + '*.*', faAnyFile, _SearchRec);
while _Finded = 0 do
begin
if (_SearchRec.Attr and faDirectory) <> 0 then
begin
if (_SearchRec.Name <> '.') and (_SearchRec.Name <> '..') then
RecursionForeachAllFiles(AMemo, AFilePath +_SearchRec.Name);
end
else
begin
AMemo.Lines.Add(AFilePath + ':' + _SearchRec.Name);
end;
_Finded := FindNext(_SearchRec);
end;
FindClose(_SearchRec);
end;
IsBreak :boolean;
begin
……
IsBreak := False;
repeat
……
while ex1 do
begin
……
if Ex2 then
begin
IsBreak := True;
break;
end;
……
end;
if IsBreak then break;
until ex3
……
end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var odds,sum:integer;
begin
sum:=0;
odds:=1;
while odds<= strtoint(Edit1.Text) do
begin
sum:=sum+odds;
odds:=odds+2;
end;
Showmessage(inttostr(sum));
end;procedure TForm1.Button2Click(Sender: TObject);
var odds,sum:integer;
begin
sum:=0;
odds:=1;
Repeat
sum:=sum+odds;
odds:=odds+2;
until odds > strtoint(Edit1.Text);
Showmessage(inttostr(sum));
end;end.
goto 和 exit都要慎用。