Chapter 17 Modifying iterations: break, next and while

In R, a standard looping sequence may be modified with the break, next and while statements.

17.2 break

The break statement is used inside a loop to terminate and exit the iteration when a certain condition is met.

for (val in x) {
    if (condition) {
        break
    }
    statement
}
%0 1:e->2:w 2:e->3:w if FALSE for x 2:n->5:w if TRUE, then exit 3:s->4:n  if FALSE 3:e->5:w if TRUE, then break 4:w->2:s 1 Start 2 Reached last val in X? for() 3 Is condition TRUE? if() 4 statement body 5 End