adplus-dvertising
frame-decoration

Question

Which of the following R code snippet stops loop after 20 iterations?

a.

for(i in 1:100) {
print(i)
if(i > 20) {
break
}
}

b.

for(i in 1:100) {
print(i)
if(i > 19) {
break
}
}

c.

for(i in 1:100) {
print(i)
if(i < 20) {
break
}
}

d.

for(i in 2:100) {
print("i")
if(i > 150) {
break
}
}

Posted under R Programming

Answer: (a).for(i in 1:100) {
print(i)
if(i > 20) {
break
}
}

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. Which of the following R code snippet stops loop after 20 iterations?