Delphi 流程控制

程序流程控制
(1)条件分之
if...else:
var I:Integer;
begin
if I > 0 then
begin
Do //不能给';'
end //没有结束 if...else都不能加';'s


else if I < 0 then
begin
//Do
end


else
begin
//Do; //两个语句以上前面的语句必须加';'
//Do
end;


end;


case of...else...end
var
I:Integer
begin
case I of
1: 
Do;//要加分号
2,3:
Do;
4..10: //如果I在4~10 包含极端 相当于 if I in[4..10]
Do;
else
Do;
end;
end;
(2)循环
while://先判断在执行(如同C艹while)
for to:
var
I:Integer;
begin
for I := 0 to do //或者 for I := 10 downto 0 do (这里每次步长只能为1 不能更改)
Do;
end;


while:
var
I := 0;
while I <= 10 do
begin
Do;
Inc(I) //自加1
end;
end;


repeat: //先执行在判断(如同C艹的do while)
var
I := 0;
repeat
Do;
Inc(I) //自加1
until I = 10;
end;


Abort:
跳出所有模块


try
 if True then
   Abrot;
except
  //处理错误消息
end; 
  Do;    //如果是 try...finally 那么这里这句就不会执行
//Abrot 之后 执行 except..end 处理异常 然后 Do


Exit: //正常退出过程
begin
try
  if True then
Exit;
finally
ShowMessage('Abrot'); //要执行
end;
showMessage('处理完成'); //不执行


Halt:(Exitcode:Integer): //非正常结束一个应用程序


RunError(Exitcode:Byte) //生成运行时错误,并结束程序


Continue: //中断当前循环
var
 i: Integer;
begin
for I := 0 to 2 do
begin
  try
if I < 2 then
Continue;
Do;
finally //这里会中断以后执行 finally..end的内容然后进入下一循环
Do;
end;
end;
end;


Brak: 完全中断循环 如果位于try...finally当中,则finally中的代码能够得到执行
var 
I: Integer;
begin
for I := 0 < 3 do
begin
try
if I = 2 then
break; //break之后还会执行 finally...end里面的内容
Do;
finally
Do;
end;
end;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值