Control flow is the order in which we code and have our statement evaluated. These allow us to control flow of execution of script inside the function.
- IF Conditional Statement: –
Decision-making is an important part of programming. This can be achieved in R programming using the conditional if…else statement.
Syntax :- If(condition )action
If conditional statements are TRUE then statement gets executed. But if conditional statement is FALSE, nothing is happen.
Here, Conditional Statement can be logical or numeric vector, but only the first element is taken into consideration.
2. IF Conditional Statement with Multiple Actions.
IF Conditional statement is TRUE then its Executed Action 1………….Action n, but if Conditional statement is FALSE then it should display message with out Execution.
Flow Chart of If condition with multiple Action:-
- If…..else Statement:-
The Else part is optional and is only evaluated if condition is FALSE. It is important to note that else must be in the same line as the closing braces of the if statement.
Flow Chart of if…..Else Condition:-
4. Nested if ………else Statement: – Placing one if statement inside another if statement is called as Nested If Else Statement in R. The If…Else Statement allows us to print Statement depending upon the Expression result (TRUE or FALSE). Some times we have to check Further when the condition is TRUE.
NOTE:-While using this Nested If….Else concept ,please be careful.
if (condition 1)
} else if (condition2)
} else if (condition3)
5. Switch Function:- Switch works in two distinct ways depending whether the first argument evaluates to a character or a number.
Text n-1=value n-1;
About Vijaya Kumar Reddy :
Vijaya Kumar Reddy is MBA in Marketing from Alliance University & B.Tech (Computer Science Engineering). Currently he is working as Analyst Intern with NikhilGuru Consulting Analytics Service LLP (Nikhil Analytics), Bangalore.