R if…else statement

R Tutorial – We shall learn about R if…else statement, its Syntax and the Execution Flow in and around the if…else statement with an R Example Script.

R if…else statement

if…else statement is an extension of if statement with an else block. So, if the condition provided to the if statement is true, then the statements in the if statement block are executed, else the statements in the else block are executed.

Following is a flow diagram depicting the flow of execution around and in an if..else statement.

R if..else statement

Syntax

if(boolean_expression){
    if_block_statements
} else {
    else_block_statements
}

The boolean_expression is any expression that evaluates to a boolean value. And if the boolean value = TRUE, execution flow enters the if block, else execution flow enters the else block.

Example

Conclusion :

In this R Tutorial, we learnt about R if…else statement, its Syntax and the Execution Flow in and around the if…else statement with an R Example Script.