R has a set of control structures that organize the flow of execution of a program, depending on the conditions of the environment. Here are the most important ones:
- If/else: This can test a condition and execute it accordingly
- for: Executes a loop that repeats for a certain number of times, as defined in the code
- while: This evaluates a condition and executes only until the condition is true
- repeat: Executes a loop an infinite number of times
- break: Used to interrupt the execution of a loop
- next: Used to jump through similar iterations to decrease the number of iterations and time taken to get the output from the loop
- return: Abandons a function
The structure of if else is as if (test_expression) { statement }.