Delphi程序流程二(for)

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    btn1: TButton;
    procedure btn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btn1Click(Sender: TObject);
var i,x,j:Integer;
begin
      j:=0;
      for i:=1 to 100 do
      begin
         x:=i+j;
         j:=x;
      end;
      ShowMessage(IntToStr(x));

      j:=0;
      for i:=100 downto 1 do
      begin
         x:=i+j;
         j:=x;
      end;
      ShowMessage(IntToStr(x));
end;

end.

1加到100的写法,顺便简单的弄了下调试方法 F5下断

不仅可以从小加到大(for x:=1 to 100 do) 还可以从大减到小 (for x:=100 downto 1do) 

posted on 2013-06-18 15:04  shellcode  阅读(160)  评论(0编辑  收藏  举报

导航