有没有办法退出单个循环,并退出所有循环?

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

我有 2 个循环,一个内循环和一个外循环。在一种情况下,我只想退出内循环以转到外循环,而在另一种情况下,我想从内循环退出到正常程序(换句话说,我想从内循环退出,而外循环并继续执行 man 程序)

有谁知道我可以同时做到这两点的方法吗?

是的,这要归功于命名循环。示例:

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;'
  …

可以找到参考资料(对于 '95 版本的语言)here