while TRUE + break in a sub-environment
<p>I'm having trouble getting a <code>while(TRUE)</code> loop to work. This example I think gets at the crux of the problem:</p>
<pre><code>l &lt;- list(x = 5)

while (TRUE){
  with(l, if (x &gt; 100) break else l$x &lt;&lt;- x + 5)
}
</code></pre>
<p>Which runs with error:</p>
<blockquote>
<p>Error in <code>eval(expr, envir, enclos)</code> :</p>
<p>no loop for break/next, jumping to top level</p>
</blockquote>
<p>Strangely, the <code>while</code> loop appears to have executed successfully:</p>
<pre><code>l
# $x
# [1] 105
</code></pre>
<p>It appears the problem is I'm sending the <code>break</code> statement in a sub-environment, since the following works as expected without error:</p>
<pre><code>x = 5

while(TRUE){
  if (x &gt; 100) break else x &lt;&lt;- x+5
}
</code></pre>
<p>Thinking it's just an environments issue, I also tried replacing <code>break</code> with <code>eval(break, parent.env())</code> and <code>eval(break, parent.frame())</code>, to no avail.</p>
<p>How can I stop this error?</p>
<hr />
<p>I suppose <code>sessionInfo()</code> may be relevant:</p>
<pre><code>R version 3.2.4 (2016-03-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.3 LTS

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] readxl_0.1.0.9000 data.table_1.9.6  haven_0.2.0      

loaded via a namespace (and not attached):
[1] rsconnect_0.4.1.11 tools_3.2.4        Rcpp_0.12.1        chron_2.3-47      
</code></pre>