如上所述,K是循环的标签。它允许你识别一个特定的循环来提高可读性,并且还可以选择性地从一组嵌套的闭环中退出一个特定的循环(即作为“goto”...嘘!:-)
这里是一个人为的例子(未编译选中):
S : Unbounded_String;
F : File_Type;
Done_With_Line : Boolean := False;
All_Done : Boolean := False;
begin
Open(F, In_File, "data_file.dat");
File_Processor:
while not End_Of_File(F) loop
S := Get_Line(F);
Data_Processor:
for I in 1 .. Length(S) loop
Process_A_Character
(Data_Char => Element(S, I), -- Mode in
Line_Done => Done_With_Line, -- Mode out
Finished => All_Done); -- Mode out
-- If completely done, leave the outermost (file processing) loop
exit File_Processor when All_Done;
-- If just done with this line of data, go on to the next one.
exit Data_Processor when Done_With_Line;
end loop;
end loop File_Processor;
Close(F);
end;
Bah。不要让可怕的“G字”吓到初学者。 'exit'不再是'if','loop'和'case'的转换。 – 2010-04-23 17:42:21