Читать книгу The Big R-Book - Philippe J. S. De Brouwer - Страница 146

4.5.2.4 Loop Control Statements

Оглавление

When the break statement is encountered inside a loop, that loop is immediately terminated and program control resumes at the next statement following the loop.

break

v <- c(1:5) for (j in v) { if (j == 3) { print(“--break--”) break } print(j) } ## [1] 1 ## [1] 2 ## [1] “--break--”

The next statement will skip the remainder of the current iteration of a loop and starts next iteration of the loop.

v <- c(1:5) for (j in v) { if (j == 3) { print(“--skip--”) next } print(j) } ## [1] 1 ## [1] 2 ## [1] “--skip--” ## [1] 4 ## [1] 5

The Big R-Book

Подняться наверх