title: Breaking out of nested loops in R
body: <p>Very simple example code (only for demonstration, no use at all):</p>
  
  <pre><code>repeat {
    while (1 &gt; 0) {
      for (i in seq(1, 100)) {
        break # usually tied to a condition
      }
      break
    }
    break
  }
  print("finished")
  </code></pre>
  
  <p>I want to break out from multiple loops without using <code>break</code> in each loop separately.
  According to <a href="https://stackoverflow.com/questions/189645/how-to-break-out-of-multiple-loops-in-python">a similar question regarding python</a>, wrapping my loops into a function seems to be a possible solution, i.e. using <code>return()</code> to break out of every loop in the function:</p>
  
  <pre><code>nestedLoop &lt;- function() {
    repeat {
      while (1 &gt; 0) {
        for (i in seq(1, 100)) {
          return()
        }
      }
    }
  }
  
  nestedLoop()
  print("finished")
  </code></pre>
  
  <p>Are there other methods available in R? Maybe something like labeling loops and then specifying which loop to break (like in Java) ?</p>