Decision Making
Decision Making structure, evaluate a condition and depending on the result some other code is processed.
There are three types of decision making statements in R
Decision Making structure, evaluate a condition and depending on the result some other code is processed.
There are three types of decision making statements in R
- If Statement
- If-Else Statement
- Switch Statement
If Statement
An if statement consists of a Boolean expression followed by one or more statement.
Syntax of is Statement :-
if(Boolean expression)
{
// Code to be executed
}
If-Else Statements
An if statement can be followed by an optional else statement, which executes when the Boolean expression is false.
The syntax of if else is :
if (Boolean_expression)
{
// Code to be executed
}
else
{
// Code to be executed
}
Example :-
Switch Statement
A switch statement allows a variable to be tested for equality against a list of values.
R has following Switch Statement :
switch (expression, case1, case2..)
→ We can have any number of cases in switch.
→ No Default is available in switch.
0 Comments:
Post a Comment