R_Code-11.r
Problem Statement
R_Code-11.r
Write a while loop that starts with a multiplier of 1. The loop should multiply the current multiplier by 4, assign it to a result variable, and print the result. The loop should exit if the result exceeds 100; otherwise, increment the multiplier by 1.
Source Code
r
# Write a while loop that starts with a multiplier of 1.
# The loop should multiply the current multiplier by 4,
# assign it to a result variable, and print the result.
# The loop should exit if the result exceeds 100; otherwise,
# increment the multiplier by 1.
num = 1
while(TRUE) {
result <- num * 4
print(result)
if (result > 100) {
break
}
num = num + 1
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16