例: for i:=0 to 1 do begin for j:=1 to 3 do begin dosomething; if j=2 then break; end; end;
跳出两个循环: n := 0; for i:=0 to 1 do begin for j:=1 to 3 do begin dosomething; if n=1 then break; end; if n=1 then break; end;
同意sysu(死树) 的方法
youexception=class(exception);try for ... for ... begin do somesthing; if ... then raise youexception.create; end; except on youexception do ... end;raise youexception
抛出异常跟GOTO实际上是一个意思
var a, b: Boolean; num1, num2: Integer; begin a := true; b := true; num1 := 0; num2 := 0; while a do begin Inc(num1); if (num1 = 10) or b then //如果跳出了第二个循环,跳出本循环 a := false; while b do begin Inc(num2); if num2 = 10 then //跳出了第二个循环 b := false; end; end
for i:=0 to 1 do
begin
for j:=1 to 3 do
begin
dosomething;
if j=2 then break;
end;
end;
n := 0;
for i:=0 to 1 do
begin
for j:=1 to 3 do
begin
dosomething;
if n=1 then break;
end;
if n=1 then break;
end;
for ...
for ...
begin
do somesthing;
if ... then
raise youexception.create;
end;
except
on youexception do ...
end;raise youexception
a, b: Boolean;
num1, num2: Integer;
begin
a := true;
b := true;
num1 := 0;
num2 := 0;
while a do
begin
Inc(num1);
if (num1 = 10) or b then //如果跳出了第二个循环,跳出本循环
a := false;
while b do
begin
Inc(num2);
if num2 = 10 then //跳出了第二个循环
b := false;
end;
end