[Rd] value of a loop broken by break

Gabor Grothendieck ggrothendieck at myway.com
Sun Dec 19 05:10:26 CET 2004

Should the 'for' loop in the following example not return 3 rather than 2?
The Language Manual says that it returns the result of the last evaluated
statement and that would be the i before the 'break'.  'repeat' and 'while'
have the same behavior.

R> (for(i in 1:10) if (i==3) { i; break } else i)
[1] 2

R> R.version.string # Windows XP
[1] "R version 2.0.1, 2004-11-04"

More information about the R-devel mailing list