-- Demonstrates a general loop with a loop and a half structure -- and the same sequence of operations implemented with a while loop with ada.text_io; use ada.text_io; with ada.integer_text_io; use ada.integer_text_io; procedure loop_and_a_half is x: integer; begin -- print squares of positive numbers loop get(x); exit when x < 0; put(x * x); -- Process x by printing its square end loop; -- Sequence of operations: get, test, process, get, test, process, get, test, exit -- The code above naturally matches the sequence of operations. -- Disadvantage: Some to never exit a loop in the middle. -- It should be clear what the exit condition is from reading the loop statement -- print squares of positive numbers, again get(x); while x > 0 loop put(x * x); -- Process x by printing its square get(x); end loop; -- Sequence of operations: get, test, process, get, test, process, get, test, exit -- Disadvantage: code to get(x) is repeated. In this case it's only one line, -- but other cases may be more complicated. end loop_and_a_half;