在循环体用什么语句退出循环? 还有....

chengxuejun1 2003-02-16 10:24:32

请看这段程序执行结果:

proceduce

begin

i:=0;
while strtodatetime('2002-12-16')+i<>date do
begin
i:=i+1;
if strtodatetime('2002-12-16')+i=strtodatetime('2003-1-16') then
begin
exit;
end;
end;

edit1.text:=inttostr(i);

end;

执行后出现怪现象Edit1.text:='Edit1';

理论上应该Edit1.text:='31'
...全文
154 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
AM_WJ 2003-02-17
  • 打赏
  • 举报
回复
to楼上的,既然已经返回值了,函数难度不结束吗?
checkyvc6 2003-02-16
  • 打赏
  • 举报
回复
exit是指退出procedure相当与c/c++里面的return;
如果要返回值可以先给result:=赋值,然后exit
大大怪老张 2003-02-16
  • 打赏
  • 举报
回复
proceduce

begin

i:=0;
while strtodatetime('2002-12-16')+i<>date do
begin
i:=i+1;
if strtodatetime('2002-12-16')+i=strtodatetime('2003-1-16') then
break;
end;

edit1.text:=inttostr(i);

end;

楼主想干什么,如果只是想得到31的话,为什么不用
strtodatetime('2003-1-16') - strtodatetime('2002-12-16') 呢
wjlsmail 2003-02-16
  • 打赏
  • 举报
回复
if strtodatetime('2002-12-16')+i=strtodatetime('2003-1-16') then
begin
Break ;
end;
delphi_xizhousheng 2003-02-16
  • 打赏
  • 举报
回复
同上!
csdnyong 2003-02-16
  • 打赏
  • 举报
回复
up!
Eastunfail 2003-02-16
  • 打赏
  • 举报
回复
被楼上的先说了 :P
belllab 2003-02-16
  • 打赏
  • 举报
回复
break退出循环体,continue跳过剩下的语句,进行下一次循环
sunware 2003-02-16
  • 打赏
  • 举报
回复
Break & continue
jakefj 2003-02-16
  • 打赏
  • 举报
回复
up

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧