我在while 循环下做了一个repeat until 循环 来查找文件,
查找中遇到某种条件要退出repeat 循环 进入到while循环中,用哪个命令。
break ,exit 试了,不行。
谢谢。

解决方案 »

  1.   

    break就可以呀,表示退出当前循环
      

  2.   

    如果比较麻烦的话,用goto语句最直接不过
      

  3.   

    用这么麻烦吗?递归不就完了
    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;
      

  4.   

    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;
      

  5.   

    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.
      

  6.   

    什么也不用,当until后面的表达式为true时自然会退出循环,在里面强制退出时才用break.
    goto 和 exit都要慎用。