Aryan PrajapatKnowledge Contributor
List and define the control statements in R.
List and define the control statements in R.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Questions | Answers | Discussions | Knowledge sharing | Communities & more.
There are three groups of control statements in R: conditional statements, loop statements, and jump statements.
Conditional statements:
if—tests whether a given condition is true and provides operations to perform if it’s so.
if-else—tests whether a given condition is true, provides operations to perform if it’s so and another set of operations to perform in the opposite case.
if… else if… else—tests a series of conditions one by one, provides operations to perform for each condition if it’s true, and a fallback set of operations to perform if none of those conditions is true.
switch—evaluates an expression against the items of a list and returns a value from the list based on the results of this evaluation.
Loop statements:
for—in for loops, iterates over a sequence.
while—in while loops, checks if a predefined logical condition (or several logical conditions) is met at the current iteration.
repeat—in repeat loops, continues performing the same set of operations until a predefined break condition (or several break conditions) is met.
Jump statements:
next—skips a particular iteration of a loop and jumps to the next one if a certain condition is met.
break—stops and exits the loop at a particular iteration if a certain condition is met.
return—exits a function and returns the result.