Search this blog

Showing posts with label Conditional Statement. Show all posts
Showing posts with label Conditional Statement. Show all posts

Monday 13 August 2018

R Decision Making - IF...ELSE Statement in R Programming

We can write a simple IF statement, IF...ELSE statements or nested IF statements as per our requirement. If you know the basics of any other programming language then after this tutorial you'll get an idea about writing conditional statements in R programming.

Flow Chart of IF...ELSE is like this

Basic Syntax of IF-ELSE is like this in R

IF (Condition 1){
Statement to execute (if condition 1 is true)
}ELSE IF (Condition 2){
Statement to execute (if condition 2 is true)
}ELSE
Statement to execute (if condition 1& 2 both are false)

For a better understanding of decision-making, statements see this example

> #Declare Variables
> a <- 20
> b <- 40
> c <- 5
>
> #Check conditions
> if(a>b && a>c){
+ print("Largest Value is A")
+
+ }else if(b>a && b>c){
+ print("Largest Value is B")
+
+ }else print("Largest Value is C-")
[1] "Largest Value is B"
>

This is how IF…ELSE works in R programming.

Cheers ðŸ™‚ Happy Learning

Thursday 22 March 2018

PL/SQL CASE Statement, Decision Making Statement in PL/SQL

Like real life in programming sometimes we need to execute some code on a specific condition, PL/SQL CASE statement allows us to execute a sequence of instructions based on a selector (A variable, function, expression etc)
and if selector value is equal to value or expression in WHEN clause then corresponding THEN clause will execute and process the statements

Wednesday 21 March 2018

PL/SQL Conditions, IF-ELSE Conditional Statement

Like other programming languages, PL/SQL supports decision making statements, These statements are also called conditional statement

Basic Syntax of IF-ELSE is like this in PL/SQL

IF (Condition 1)

THEN

Statement to execute (if condition 1 is true)

ELSIF (Condition 2)

THEN

Statement to execute (if condition 2 is true)

ELSE

Statement to execute (if condition 1& 2 both are false)

END IF;

For a better understanding of concept look at these examples