For Loop in R Programming
Premium
R has three statements that provide explicit looping. They are for
, while
and repeat
. Each of the three statements returns the value of the last statement that was evaluated. R also provides other functions for implicit looping such as tapply
, apply
, and lapply
.
There are two statements that can be used to explicitly control looping. They are break
and next
. The break statement causes an exit from the innermost loop that is currently being executed. The next statement immediately causes control to return to the start of the loop. The next iteration of the loop (if there is one) is then executed. No statement below next
in the current loop is evaluated.
Unlock Premium Content
Upgrade your account to access the full article, downloads, and exercises.
You'll get access to:
- Access complete tutorials and examples
- Download source code and resources
- Follow along with practical exercises
- Get in-depth explanations