procedure TForm1.FormCreate(Sender: TObject);
var
  x,y,count:Integer;
begin
  x:= 0;
  y:=0;
  count:=0;
  while True do begin
    if x=100 then Break;
    while True do begin
      if y=100 then Break;
      Inc(count);
      Inc(y);
    end;
    Inc(x);
  end;
  ShowMessage(IntToStr(count));//100
end;
怎么是100 呢?

解决方案 »

  1.   

    为什么不是呢?你的意思为什么count到100不自加了吧?Y的循环break后,count就不+了。
      

  2.   


    procedure TForm1.FormCreate(Sender: TObject);
    var
      x,y,count:Integer;
    begin
      x:= 0;
      y:=0;
      count:=0;
      while True do begin
        if x=100 then Break;
        y :=0;
        while True do begin
          if y=100 then Break;
          Inc(count);
          Inc(y);
        end;
        Inc(x);
      end;
      ShowMessage(IntToStr(count)); //10000
    end;y 没复位 呵呵
      

  3.   

        while True do begin
          if y=100 then Break;
          Inc(count);
          Inc(y);
        end;
    之后count就为100了 ,接着在外层的循环,每次进入内层之后直接break了,count不在增加。
      

  4.   


    简化成  count:=0;
        y :=0;
        while True do begin
          if y=100 then Break;
          Inc(count);
          Inc(y);      //看出y是跟count同步的
        end;
      

  5.   

    还以为LZ不知道break呢,原来是我错了。
      

  6.   

    y值第二次以后总会保持100。lz应该是忘记了y值在循环前面复位了
      

  7.   

    y第一次循环到底就变成了100
    if y=100 then
    就一直成立了,就Break内层循环!