What will be the output of the following code: for(i in 1:3) { print(i) }?

What will be the output of the following code: for(i in 1:3) { print(i) }?

a) 1 2 3
b) 3 2 1
c) Error
d) None of the above

Answer:

a) 1 2 3

Explanation:

The for loop iterates through the sequence 1:3 and prints each value (1, 2, and 3).

Reference:

R Programming – Loops MCQ Questions and Answers

Scroll to Top