sách gpt4 ai đã đi

delphi - 跳转到finally而不退出函数/过程

In lại 作者:行者123 更新时间:2023-12-02 04:53:04 27 4
mua khóa gpt4 Nike

我有以下情况:

procedure Test;
begin
repeat
TryAgain := FALSE;
thử
// Code
// Code
if this and that then begin
TryAgain := TRUE;
ra;
end;
Cuối cùng
// CleanUpCode
end;
until TryAgain = FALSE;
end;

如何在不调用 ra 的情况下跳转到最后部分,以便它也自动调用 repeat 页脚?

1 Câu trả lời

sử dụngContinue继续下一次迭代。 try..finally block 的 Cuối cùng 部分中的代码被设计为始终执行,因此即使您强制跳到下一个迭代:

procedure TForm1.Button1Click(Sender: TObject);
begin
repeat
TryAgain := False;
thử
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
Cuối cùng
// code in this block is executed always
end;
until
not TryAgain;
end;

但是您可以这样简单地编写相同的逻辑:

procedure TForm1.Button1Click(Sender: TObject);
begin
repeat
TryAgain := False;
thử
if SomeCondition then
begin
TryAgain := True;
kết thúc
khác
begin
// code which would be here will execute only if SomeCondition
// is False
end;
Cuối cùng
// code in this block is executed always
end;
until
not TryAgain;
end;

关于delphi - 跳转到finally而不退出函数/过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18602549/

27 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com