Control Structure

Control structures in R allow you to control the flow of execution of a series of R expressions. Basically, control structures allow you to put some “logic” into your R code, rather than just always executing the same R code every time. Control structures allow you to respond to inputs or to features of the data and execute different R expressions accordingly.

Here are the Commonly used control structures in R:

  1. if and else: testing a condition and acting on it
  2. for: execute a loop a fixed number of times
  3. while: execute a loop while a condition is true
  4. repeat: execute an infinite loop (must break out of it to stop)
  5. break: break the execution of a loop
  6. next: skip an iteration of a loop

Most control structures are not used in interactive sessions, but rather when writing functions or longer expressions. However, these constructs do not have to be used in functions and it’s a good idea to become familiar with them before we delve into functions.

In the following section one by one control structure will be discussed.

JSON Files in R

If-else condition