下面的例子是一个使用goto造成的死循环,一般来讲并不建议使用goto语句,从软件工程的角度上讲,过多的使用goto语句会导致程序的控制流难以跟踪,使程序难以理解和难以修改。
with Ada.Text_IO;
use Ada.Text_IO;
procedure GoTODemo is
begin
goto Some_Place;
<<There>>
Put_Line("I am now at the There place");
goto Stop_This_Mess;
<<Where>>
Put_Line("I am now at the Where place");
<<Some_Place>>
Put_Line("I am now someplace");
goto Where;
<<Stop_This_Mess>>
Put_Line("I am now about to end this mess.");
end GoTODemo;