Loops/Continue: Difference between revisions
Content added Content deleted
Line 102: | Line 102: | ||
<<Continue>> --Ada 2012 no longer requires a statement after the label |
<<Continue>> --Ada 2012 no longer requires a statement after the label |
||
end loop; |
end loop; |
||
end Loop_Continue;</lang> |
|||
'''N.''' This is a more true-to-Ada strategy for 'continue' comprising of an outer iteration loop and an inner labeled single-pass loop. This is a safer strategy than using goto which could be problematic when dealing with complex nested loops. |
|||
<lang ada>with Ada.Text_IO; |
|||
use Ada.Text_IO; |
|||
procedure Loop_Continue is |
|||
begin |
|||
Print_All: |
|||
for I in 1 .. 10 loop |
|||
Print_Element: loop |
|||
Put (Integer'Image(I)); |
|||
if I = 5 or I = 10 then |
|||
New_Line; |
|||
exit Print_Element; |
|||
end if; |
|||
Put (","); |
|||
exit Print_Element; |
|||
end loop Print_Element; |
|||
end loop Print_All; |
|||
end Loop_Continue;</lang> |
end Loop_Continue;</lang> |
||