num:=fun();
if num-1<0 then 
for i := 0 to num-1 do
begin
    ......
end;

解决方案 »

  1.   

    呀~错了,是
    if num>0 then ……
      

  2.   

    if num>0 then 
      begin
        for i:=0 to num-1 do
          begin
            .
            .
            .
          end;
      end
    else ..........;
    看一看行不行
      

  3.   

    如果我没有记错的话,在C或者是BASIC语中的FOR循环是允许初值比末值大的。其中有一个Step如果为正的话,则初值应小于末值;为负,则初值应大于末值。Delphi中未曾用到这样的循环,估计也是能行的,不信你可以在begin和end之间加入一输入显示i值的函数,i就是从大到小了。
    见识粗浅,我也不知道是不是这样的。
      

  4.   

    不可能!!!!!!
    一定是你的num计算有误。
      

  5.   

    用F7跟踪一下
    不会的话可在循环中加showmessage(inttostr(i));看看i的值到底是不是小于0
      

  6.   

    不可能!!!!!!
    一定是你的num计算有误。 
      

  7.   

    不可能!!!!!!
    一定是你的num计算有误。 执行FOR 
    以前先SHOWMESSAGE(INTTOSTR(NUM))看看会不会
    出现你所说的问题。
      

  8.   

    num:=fun();
    if num-1<0 then 
    for i := 0 to num-1 do
    begin
        ......
    end; 
      

  9.   

    谢谢大家的参与,我发现问题出在我的num类型定义上,请看一下程序:
    该程序中,showmessage将被执行。若将num,i的声明改为integer型,则showmessage不会被执行。
    虽然找到了问题,但我不明白,word表示无符号数,integet表示有符号数,但是无论如何,num-1总是小于0的,for语句怎么会执行呢?unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      num :  word;
    implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);
    var
        i:word;
    begin
        num := 0;
        for i:=0 to num-1 do
        begin
            showmessage('Hello!');
        end;
        
    end;
    end.