May 12, 2021 R language tutorial
There may be a situation when you need to execute a piece of code several times. T ypically, statements are executed sequentially. T he first statement in the function is executed first, then the second statement, and so on.
Programming languages provide a variety of control structures that allow for more complex execution paths.
Loop statements allow us to execute a statement or set of statements multiple times, as is the general form of circular statements in most programming languages -
The R programming language provides the following kinds of loops to handle loop requirements. C lick the link below to check its details.
Sr.No. | The type and description of the loop |
---|---|
1 |
Repeat loop
Execute a series of statements multiple times and simplify the code that manages circular variables. |
2 |
While loop
Repeat a statement or group of statements when a given condition is true. I t tests the condition before executing the loop body. |
3 |
For loop
Like a while statement, the difference is that it tests the conditions at the end of the loop body. |
The loop control statement changes execution from its normal sequence.
When execution leaves the scope, all automatic objects created in that scope are destroyed.
The R language supports the following control statements.
Click the link below to check its details.
Sr.No. | Control statements and descriptions |
---|---|
1 |
Break statement
The statement that terminates the loop and transfers the execution to the statement that is executed immediately after the loop. |
2 |
Next statement
The next statement simulates the behavior of the R-language switch statement. |