Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 6

Programming Constructs

 Operators
 Decision control statements
 Loops

R programming - Pratik Gadia


Operators

Arithmetic Logical Relational


+ & ==
- | !=
* ! <
/ <=
** ^ >
%% >=

R programming - Pratik Gadia


Operators

Logical operators
a !a
NOT TRUE FALSE
FALSE TRUE

AND OR
a b a&b a b a|b
TRUE TRUE TRUE TRUE TRUE TRUE
TRUE FALSE FALSE TRUE FALSE TRUE
FALSE TRUE FALSE FALSE TRUE TRUE
FALSE FALSE FALSE FALSE FALSE FALSE
R programming - Pratik Gadia
Decision control

 Branching – decision control statements


 Follow a branch based on condition

 Types of decision control statements:


o If
o If…else
o If…else if...else
o switch

R programming - Pratik Gadia


Decision control

if x>0 if x>0 if x>0


+ve +ve +ve
else if x<0
else
-ve
Not
else
+ve
R programming - Pratik Gadia zero
Loops

 To iterate over a sequence


 To loop through, cycle through a set of statements multiple times

 Types of loops:
o Repeat – Looped at least once
o While – Condition is validated to begin with loop
o For – Iterate over a sequence

R programming - Pratik Gadia

You might also like