CONTROL STRUCTURES IN R
Control structures in R are fundamental programming constructs used to control the flow of execution in code, allowing programmers to implement logic and make decisions based on specific conditions
CONDITIONAL STRUCTURES
Conditional structures are used to execute blocks of code if a specific condition is met. These structures allow you to make decisions within a program, executing certain actions only if certain conditions are met
If else
if(cond) cons.expr else alt.expr
ifelse function
ifelse(test, yes, no)
The switch function
switch(EXPR, ...)
LOOPS
Loops are used to repeatedly execute a block of code, either a specific number of times or as long as a condition is met. They allow you to automate repetitive tasks without having to write the same code multiple times
For loop
for(var in seq) expr
break and next functions
break next
While loop
while(cond) expr
The repeat loop
repeat expr
FLOW CONTROL
These functions allow you to pause execution or handle exceptions and errors in a controlled manner during R code execution. In addition, a related tutorial is included for creating progress bars, as these are useful tools for visualizing the execution of a process or iteration in loops, which can improve the understanding of the program flow