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

3 ada

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

有谁知道我可以做到这两种方式?

Ond*_*cny 5

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

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;'
  …
Run Code Online (Sandbox Code Playgroud)

参考(适用于该语言的'95版本)可以在此处找到。