Skip to main content

Control Structures In R Programming — Part 1 MCQs with Explanations

Practice high-yield Programming & Software Development MCQs on Control Structures In R Programming — Part 1 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.

Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40

Verified Practice Questions

Interactive test mode with detailed academic worked solutions

Live Progress | 0/40 answered
✓ 0 correct ✗ 0 wrong 0% score
Question 1 of 40
★ FPSC ★ PPSC

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

Question 2 of 40
★ FPSC ★ PPSC

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

Question 3 of 40
★ FPSC ★ PPSC

How is the switch() function used in R?

Question 4 of 40
★ FPSC ★ PPSC

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

Question 5 of 40
★ FPSC ★ PPSC

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

Question 6 of 40
★ FPSC ★ PPSC

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

Question 7 of 40
★ FPSC ★ PPSC

What does the next statement do in R?

Question 8 of 40
★ FPSC ★ PPSC

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

Question 9 of 40
★ FPSC ★ PPSC

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

Question 10 of 40
★ FPSC ★ PPSC

In R, what is the role of the ifelse() function?

Question 11 of 40
★ FPSC ★ PPSC

How is a do-while loop implemented in R?

Question 12 of 40
★ FPSC ★ PPSC

In R, what does the if (condition) { code_block } else { code_block } statement do?

Question 13 of 40
★ FPSC ★ PPSC

How is the repeat loop terminated in R?

Question 14 of 40
★ FPSC ★ PPSC

What is the purpose of the which() function in R?

Question 15 of 40
★ FPSC ★ PPSC

How do you create a vector containing the first 5 positive even numbers in R using a loop?

Question 16 of 40
★ FPSC ★ PPSC

What is the output of the following R code: for (i in 1:5) { if (i %% 2 == 0) { print(i) } }

Question 17 of 40
★ FPSC ★ PPSC

In R, what is the purpose of the repeat loop combined with break?

Question 18 of 40
★ FPSC ★ PPSC

How is the switch() function different from if-else in R?

Question 19 of 40
★ FPSC ★ PPSC

What is the role of the next statement in a loop in R?

Question 20 of 40
★ FPSC ★ PPSC

In R, what does the repeat loop combined with next do?

Question 21 of 40
★ FPSC ★ PPSC

How do you create a vector containing the first 5 prime numbers in R using a while loop?

Question 22 of 40
★ FPSC ★ PPSC

In R, what is the purpose of the ifelse() function?

Question 23 of 40
★ FPSC ★ PPSC

How is the for loop different from the while loop in R?

Question 24 of 40
★ FPSC ★ PPSC

What does the Sys.sleep(2) function do in R?

Question 25 of 40
★ FPSC ★ PPSC

In R, how do you create an infinite loop?

Question 26 of 40
★ FPSC ★ PPSC

What is the output of the following R code: x <- 5; while (x > 0) { print(x); x <- x - 2 }

Question 27 of 40
★ FPSC ★ PPSC

In R, how do you create a switch statement with a default case?

Question 28 of 40
★ FPSC ★ PPSC

How do you create a loop that prints the squares of numbers from 1 to 10 in R?

Question 29 of 40
★ FPSC ★ PPSC

In R, what is the purpose of the next statement in a loop?

Question 30 of 40
★ FPSC ★ PPSC

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

Question 31 of 40
★ FPSC ★ PPSC

A function, together with an environment, makes up what is called a . . . . . . . . closure.

Question 32 of 40
★ FPSC ★ PPSC

Body of lapply function is?

Question 33 of 40
★ FPSC ★ PPSC

. . . . . . . . is used to break the execution of a loop.

Question 34 of 40
★ FPSC ★ PPSC

Write a function to extract the first name in the string "Mrs. Jake Luther"?

Question 35 of 40
★ FPSC ★ PPSC

Which of the following R code will print the following result? [[1]] [1] 2.263808 [[2]] [1] 1.314165 9.815635 [[3]] [1] 3.270137 5.069395 6.814425 [[4]] [1] 0.9916910 1.1890256 0.5043966 9.2925392

Question 36 of 40
★ FPSC ★ PPSC

What will be the output of the following R code? > f <- function(num) { + hello <- "Hello, world!\n" + for(i in seq_len(num)) { + cat(hello) + } + chars <- nchar(hello) * num + chars + } > meaningoflife <- f(3) > print(meaningoflife)

Question 37 of 40
★ FPSC ★ PPSC

. . . . . . . . function is same as lapply in R.

Question 38 of 40
★ FPSC ★ PPSC

What would be the value of following R expression? log(-1)

Question 39 of 40
★ FPSC ★ PPSC

The . . . . . . . . for R are the main feature that make it different from the original S language.

Question 40 of 40
★ FPSC ★ PPSC

What will be the output of the following R code? > f <- function(elt) { + elt[, 1] + } > lapply(x, f)

✓ Link copied to clipboard
Continue Your Practice

Advance Html — Part 1

Master the next curriculum module with 40 exam-standard MCQs.

Next Practice Set →

💡 Examiner's Advisory for Programming & Software Development

In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.

More Modules in Programming & Software Development

View All →
📚

Study Guides

Topic summaries and syllabus breakdown

Explore Guides →
🎯

Complete Library

Search through 78,000+ verified MCQs

Browse Library →
📱

Mobile App

Offline mock tests and instant bookmarks

Get Mobile App →