Q. What is the output of the following R code: for (i in 1:5) { if (i == 3) next; print(i) }

  • (A) 1, 2, 4, 5
  • (B) 1, 2, 3, 4, 5
  • (C) 2, 4
  • (D) 0, 1, 2, 3, 4
πŸ’¬ Discuss
βœ… Correct Answer: (A) 1, 2, 4, 5

Q. Which control structure in R is used to execute a block of code repeatedly until a condition is met?

  • (A) if-else loop
  • (B) for loop
  • (C) while loop
  • (D) do-while loop
πŸ’¬ Discuss
βœ… Correct Answer: (C) while loop

Q. In R, what is the purpose of the if-else statement?

  • (A) To execute a block of code if a condition is true, otherwise execute another block of code
  • (B) To create a loop that iterates a specified number of times
  • (C) To check multiple conditions sequentially
  • (D) To execute a block of code repeatedly until a condition is met
πŸ’¬ Discuss
βœ… Correct Answer: (A) To execute a block of code if a condition is true, otherwise execute another block of code

Q. How is the switch() function used in R?

  • (A) To toggle between TRUE and FALSE values
  • (B) To switch the positions of two elements
  • (C) To select one of several alternatives
  • (D) To change the direction of a loop
πŸ’¬ Discuss
βœ… Correct Answer: (C) To select one of several alternatives

Q. In R, what is the syntax for the for loop?

  • (A) for (i in 1:10) { code_block }
  • (B) for (i = 1 to 10) { code_block }
  • (C) for (i = 1; i <= 10; i++) { code_block }
  • (D) for (i from 1 to 10) { code_block }
πŸ’¬ Discuss
βœ… Correct Answer: (A) for (i in 1:10) { code_block }

Q. What is the purpose of the break statement in a loop in R?

  • (A) To exit the loop immediately
  • (B) To skip the current iteration of the loop
  • (C) To restart the loop from the beginning
  • (D) To increment the loop variable
πŸ’¬ Discuss
βœ… Correct Answer: (A) To exit the loop immediately

Q. How is a while loop different from a for loop in R?

  • (A) while loop is used for fixed iterations, for loop for variable iterations
  • (B) for loop is used for fixed iterations, while loop for variable iterations
  • (C) Both while and for loops are used for fixed iterations
  • (D) Both while and for loops are used for variable iterations
πŸ’¬ Discuss
βœ… Correct Answer: (B) for loop is used for fixed iterations, while loop for variable iterations

Q. What does the next statement do in R?

  • (A) Jumps to the next iteration of the loop
  • (B) Ends the loop immediately
  • (C) Skips the next condition in an if-else statement
  • (D) Moves to the next element in a vector
πŸ’¬ Discuss
βœ… Correct Answer: (A) Jumps to the next iteration of the loop

Q. In R, what is the purpose of the repeat loop?

  • (A) To repeat a block of code until a certain condition is met
  • (B) To repeat a block of code a specified number of times
  • (C) To repeat a block of code indefinitely
  • (D) To repeat a block of code based on a specific condition
πŸ’¬ Discuss
βœ… Correct Answer: (C) To repeat a block of code indefinitely

Q. What is the result of the expression 5 %% 2 in R?

  • (A) 1
  • (B) 2
  • (C) 2.5
  • (D) 0.5
πŸ’¬ Discuss
βœ… Correct Answer: (A) 1