SNO | STATEMENT | DESCRIPTION | EXAMPLE |
---|---|---|---|
1 | IF | This statement can be used to test a condition & the result can be used to make decision with the keyword IF. |
x <-10 y<-15 if(y>x> { cat(x,"is a smaller number than\n",y> } Output:10 is a smaller number than 15 |
2 | IF ELSE | This statement can be used when previous statement was not TRUE. |
x1 = 11 if(x1 %% 2 == 0> { cat(x1,"is an Even number"> } else { cat(x1,"is an Odd number"> } Output:11 is an Odd number |
3 | ELSE if | This statement can be used when previous statement was not TRUE. |
x <- 100 y <- 100 if (y > x> { print("y is greater than x"> } else if (x == y> { print ("x and y are equal"> } Output:[1] "x and y are equal" |