unit Unit1;
interface
uses
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.
interface
uses
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.
while..do是条件先行,repeat..until是条件后行,所以repeat..until的语法段里面至少要运行一次,Delphi给人的感觉学习起来没什么难度,主要还是有别的语言的基础吧,也主要是自己做多了面向对象的开发,总觉得Delphi7的IDE差微软的DOTNET级别的IDE远多了,用起来不是很顺手。