R: if statement

As in other programming languages if a statement is very useful so it can also be useful in R. This statement is the type of decision-making statement in R. 

If the given condition is true, then the set of statements will get executed but if the condition is a false set of statements will not get executed. 

Syntax

if (condition) {
   set of statements 
}

Flowchart

R If condition

Example

a <-4
if( a%%2==0 )#condition
{
  print("Even Number")  # Statement
}

Output:

[1] "Even Number"