用于Continue
进行下一次迭代。finally
块部分中的代码try..finally
设计为始终执行,因此即使您强制跳到下一次迭代:
procedure TForm1.Button1Click(Sender: TObject);
begin
repeat
TryAgain := False;
try
if SomeCondition then
begin
TryAgain := True;
// this will proceed the finally block and go back to repeat
Continue;
end;
// code which would be here will execute only if SomeCondition
// is False, because calling Continue will skip it
finally
// code in this block is executed always
end;
until
not TryAgain;
end;
但是同样的逻辑你可以简单地这样写:
procedure TForm1.Button1Click(Sender: TObject);
begin
repeat
TryAgain := False;
try
if SomeCondition then
begin
TryAgain := True;
end
else
begin
// code which would be here will execute only if SomeCondition
// is False
end;
finally
// code in this block is executed always
end;
until
not TryAgain;
end;