-
Notifications
You must be signed in to change notification settings - Fork 0
/
Flow Control.R
55 lines (48 loc) · 903 Bytes
/
Flow Control.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
##### IF Statement #####
if (2<3) {
print("The if statement executed!")
} else {
print("The else statement executed!")
}
if (2>3) {
print("The if statement executed!")
} else {
print("The else statement executed!")
}
if (2>3) {
print("The if statement executed!")
} else if (2<3) {
print("The else if statement executed!")
} else {
print("The else statement executed!")
}
##### Switch Statement #####
#Based on Index
num=1
result <- switch(num,
"One",
"Two",
"Three")
result
##### Switch Statement #####
#Based on Matching Value
num="1"
result <- switch(num,
"1"="One",
"2"="Two",
"3"="Three",
"I cannot recognize!")
result
##### While Statement #####
a=1
b=5
while (b>a) {
print("a<b")
print(paste("a =",a))
print(paste("b =",b))
a=a+1
}
##### For Statement #####
for (i in 1:5) {
print(i)
}