其他分享
首页 > 其他分享> > Delphi 系统[9]关键字和保留字 for、to、downto、do、while、repeat、until

Delphi 系统[9]关键字和保留字 for、to、downto、do、while、repeat、until

作者:互联网

Delphi 系统[9]关键字和保留字  for、to、downto、do、while、repeat、until

1、定义:

2、示例:

{ for 循环语句,循环变量递增 to } 
procedure TForm1.Button1Click(Sender: TObject); 
var 
  I, iSum: Integer; 
begin 
  iSum := 0; 
  for I := 1 to 100 do 
    iSum := iSum + I; 
  Caption := IntToStr(iSum);  { 结果: 5050 } 
end; 
 
{ for 循环语句,循环变量递减 downto } 
procedure TForm1.Button1Click(Sender: TObject); 
var 
  I, iSum: Integer; 
begin 
  iSum := 0; 
  for I := 100 downto 1 do 
    iSum := iSum + I; 
  Caption := IntToStr(iSum);  { 结果: 5050 } 
end; 
 

{ while 语句 } 
procedure TForm1.Button1Click(Sender: TObject); 
var 
  I, iSum: Integer; 
begin 
  iSum := 0; 
  I := 0; 
  while I <= 100 do begin 
    iSum := iSum + I; 
    Inc(I); 
  end; 
  Caption := IntToStr(iSum);  { 结果:5050 } 
end; 
 

{ repeat 语句 } 
procedure TForm1.Button1Click(Sender: TObject); 
var 
  I, iSum: Integer; 
begin 
  iSum := 0; 
  I := 0; 
  repeat 
    iSum := iSum + I; 
    Inc(I); 
  until I > 100; 
  Caption := IntToStr(iSum);  { 结果: 5050 } 
end; 

  

 

 

 

创建时间:2021.08.11  更新时间:

标签:语句,do,repeat,..,iSum,downto,while,保留字
来源: https://www.cnblogs.com/guorongtao/p/15127223.html