Home » R If else statement

R If else statement

by Online Tutorials Library

If-else statement

In the if statement, the inner code is executed when the condition is true. The code which is outside the if block will be executed when the if condition is false.

There is another type of decision-making statement known as the if-else statement. An if-else statement is the if statement followed by an else statement. An if-else statement, else statement will be executed when the boolean expression will false. In simple words, If a Boolean expression will have true value, then the if block gets executed otherwise, the else block will get executed.

R programming treats any non-zero and non-null values as true, and if the value is either zero or null, then it treats them as false.

The basic syntax of If-else statement is as follows:

Flow Chart

R If-else statement

Example 1

Output:

R If-else statement

Example 2

Output:

R If-else statement

Example 3

Output:

R If-else statement

Example 4

Output:

R If-else statement

Example 5

Output:

R If-else statement


Next Topicelse if statement

You may also like