Is there a way to exit a single loop, and exit all loops?

ada

Solution

Yes, this is possible thanks to named loops. Example:

Outer_Loop:
  loop
    -- first inner loop
    loop
      …

      -- exit the inner loop when a condition is met
      exit when Check_Condition();

      …
      end loop;

    -- second inner loop
    loop
      …

      -- exit the *outer* loop, in this example unconditionally
      exit Outer_Loop;

      -- or you can combine it with a condition
      exit Outer_Loop when Another_Condition_Met();

      …
      end loop;
    end loop Outer_Loop;

  -- execution will continue here after 'exit Outer_Loop;'
  …

Reference (for the '95 version of the language) can be found here.

Problem

I have 2 loops an inner loop and outer loop. In one case I want to just exit the inner loop to go to the outer loop and in the other I want to exit from the inner loop to the normal program (in other words from the inner loop I want to exit it and the outer loop and continue execution on the man program) Does anyone know a way I can do these both?

Original source