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
🎉 Set complete! All 40 questions answered.
Question 1 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which control structure in R is used to execute a block of code repeatedly until a condition is met?
Correct Answer: Option C — while loop
Detailed Academic Explanation:
while loop is the correct answer to “Which control structure in R is used to execute a block of code repeatedly until a condition is met”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In R, what is the purpose of the if-else statement?
Correct Answer: Option A — To execute a block of code if a condition is true, otherwise execute another block of code
Detailed Academic Explanation:
To execute a block of code if a condition is true, otherwise execute another block of code is the correct answer to “In R, what is the purpose of the if-else statement”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How is the switch() function used in R?
Correct Answer: Option C — To select one of several alternatives
Detailed Academic Explanation:
To select one of several alternatives is the correct answer to “How is the switch() function used in R”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In R, what is the syntax for the for loop?
Correct Answer: Option A — for (i in 1:10) { code_block }
Detailed Academic Explanation:
for (i in 1:10) { code_block } is the correct answer to “In R, what is the syntax for the for loop”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the break statement in a loop in R?
Correct Answer: Option A — To exit the loop immediately
Detailed Academic Explanation:
To exit the loop immediately is the correct answer to “What is the purpose of the break statement in a loop in R”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How is a while loop different from a for loop in R?
Correct Answer: Option B — for loop is used for fixed iterations, while loop for variable iterations
Detailed Academic Explanation:
for loop is used for fixed iterations, while loop for variable iterations is the correct answer to “How is a while loop different from a for loop in R”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the next statement do in R?
Correct Answer: Option A — Jumps to the next iteration of the loop
Detailed Academic Explanation:
Jumps to the next iteration of the loop is the correct answer to “What does the next statement do in R”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In R, what is the purpose of the repeat loop?
Correct Answer: Option C — To repeat a block of code indefinitely
Detailed Academic Explanation:
To repeat a block of code indefinitely is the correct answer to “In R, what is the purpose of the repeat loop”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the result of the expression 5 %% 2 in R?
Correct Answer: Option A — 1
Detailed Academic Explanation:
1 is the correct answer to “What is the result of the expression 5 %% 2 in R”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In R, what is the role of the ifelse() function?
Correct Answer: Option A — To check a single condition and execute different code based on the result
Detailed Academic Explanation:
To check a single condition and execute different code based on the result is the correct answer to “In R, what is the role of the ifelse() function”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How is a do-while loop implemented in R?
Correct Answer: Option A — do { code_block } while (condition)
Detailed Academic Explanation:
do { code_block } while (condition) is the correct answer to “How is a do-while loop implemented in R”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In R, what does the if (condition) { code_block } else { code_block } statement do?
Correct Answer: Option A — Executes code_block if the condition is true, otherwise executes the else block
Detailed Academic Explanation:
Executes code_block if the condition is true, otherwise executes the else block is the correct answer to “In R, what does the if (condition) { code_block } else { code_block } statement do”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How is the repeat loop terminated in R?
Correct Answer: Option A — Using the break statement
Detailed Academic Explanation:
Using the break statement is the correct answer to “How is the repeat loop terminated in R”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the which() function in R?
Correct Answer: Option B — To identify the positions of elements satisfying a condition
Detailed Academic Explanation:
To identify the positions of elements satisfying a condition is the correct answer to “What is the purpose of the which() function in R”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you create a vector containing the first 5 positive even numbers in R using a loop?
Correct Answer: Option A — even_numbers <- numeric(5); for (i in 1:5) { even_numbers[i] <- 2 * i }
Detailed Academic Explanation:
even_numbers <- numeric(5); for (i in 1:5) { even_numbers[i] <- 2 * i } is the correct answer to “How do you create a vector containing the first 5 positive even numbers in R using a loop”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following R code: for (i in 1:5) { if (i %% 2 == 0) { print(i) } }
Correct Answer: Option C — 2, 4
Detailed Academic Explanation:
2, 4 is the correct answer to “What is the output of the following R code: for (i in 1:5) { if (i %% 2 == 0) { print(i) } }”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In R, what is the purpose of the repeat loop combined with break?
Correct Answer: Option D — To exit the loop immediately
Detailed Academic Explanation:
To exit the loop immediately is the correct answer to “In R, what is the purpose of the repeat loop combined with break”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How is the switch() function different from if-else in R?
Correct Answer: Option A — switch() is used for multiple conditions, if-else for two conditions
Detailed Academic Explanation:
switch() is used for multiple conditions, if-else for two conditions is the correct answer to “How is the switch() function different from if-else in R”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the role of the next statement in a loop in R?
Correct Answer: Option C — To move to the next iteration of the loop
Detailed Academic Explanation:
To move to the next iteration of the loop is the correct answer to “What is the role of the next statement in a loop in R”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In R, what does the repeat loop combined with next do?
Correct Answer: Option C — Repeats a block of code a specified number of times and skips to the next iteration
Detailed Academic Explanation:
Repeats a block of code a specified number of times and skips to the next iteration is the correct answer to “In R, what does the repeat loop combined with next do”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you create a vector containing the first 5 prime numbers in R using a while loop?
Correct Answer: Option A — primes <- numeric(5); num <- 2; while (length(primes) < 5) { if (all(num %% 2:(num-1) != 0)) { primes <- c(primes, num) } num <- num + 1 }
Detailed Academic Explanation:
primes <- numeric(5); num <- 2; while (length(primes) < 5) { if (all(num %% 2:(num-1) != 0)) { primes <- c(primes, num) } num <- num + 1 } is the correct answer to “How do you create a vector containing the first 5 prime numbers in R using a while loop”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In R, what is the purpose of the ifelse() function?
Correct Answer: Option B — To check a single condition and execute different code based on the result
Detailed Academic Explanation:
To check a single condition and execute different code based on the result is the correct answer to “In R, what is the purpose of the ifelse() function”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How is the for loop different from the while loop in R?
Correct Answer: Option A — for loop is used for fixed iterations, while loop for variable iterations
Detailed Academic Explanation:
for loop is used for fixed iterations, while loop for variable iterations is the correct answer to “How is the for loop different from the while loop in R”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the Sys.sleep(2) function do in R?
Correct Answer: Option A — Pauses the execution of R for 2 seconds
Detailed Academic Explanation:
Pauses the execution of R for 2 seconds is the correct answer to “What does the Sys.sleep(2) function do in R”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In R, how do you create an infinite loop?
Correct Answer: Option B — while (TRUE) { code_block }
Detailed Academic Explanation:
while (TRUE) { code_block } is the correct answer to “In R, how do you create an infinite loop”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following R code: x <- 5; while (x > 0) { print(x); x <- x - 2 }
Correct Answer: Option B — 5, 4, 3, 2, 1
Detailed Academic Explanation:
5, 4, 3, 2, 1 is the correct answer to “What is the output of the following R code: x <- 5; while (x > 0) { print(x); x <- x - 2 }”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In R, how do you create a switch statement with a default case?
switch(case_expression, case1 = expr1, case2 = expr2, default = default_expr) is the correct answer to “In R, how do you create a switch statement with a default case”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
How do you create a loop that prints the squares of numbers from 1 to 10 in R?
Correct Answer: Option A — for (i in 1:10) { print(i^2) }
Detailed Academic Explanation:
for (i in 1:10) { print(i^2) } is the correct answer to “How do you create a loop that prints the squares of numbers from 1 to 10 in R”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In R, what is the purpose of the next statement in a loop?
Correct Answer: Option C — Moves to the next iteration of the loop
Detailed Academic Explanation:
Moves to the next iteration of the loop is the correct answer to “In R, what is the purpose of the next statement in a loop”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following R code: for (i in 1:5) { if (i == 3) next; print(i) }
Correct Answer: Option A — 1, 2, 4, 5
Detailed Academic Explanation:
1, 2, 4, 5 is the correct answer to “What is the output of the following R code: for (i in 1:5) { if (i == 3) next; print(i) }”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
A function, together with an environment, makes up what is called a . . . . . . . . closure.
Correct Answer: Option B — function
Detailed Academic Explanation:
function is the correct answer to “A function, together with an environment, makes up what is called a . . . . . . . . closure.”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Body of lapply function is?
Correct Answer: Option A — function (X, FUN, ...) { FUN <- match.fun(FUN) if (!is.vector(X) || is.object(X)) X <- as.list(X) .Internal(lapply(X, FUN)) }
Detailed Academic Explanation:
function (X, FUN, ...) { FUN <- match.fun(FUN) if (!is.vector(X) || is.object(X)) X <- as.list(X) .Internal(lapply(X, FUN)) } is the correct answer to “Body of lapply function is”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
. . . . . . . . is used to break the execution of a loop.
Correct Answer: Option C — break
Detailed Academic Explanation:
break is the correct answer to “. . . . . . . . is used to break the execution of a loop.”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Write a function to extract the first name in the string "Mrs. Jake Luther"?
Correct Answer: Option B — Substr
Detailed Academic Explanation:
Substr is the correct answer to “Write a function to extract the first name in the string "Mrs. Jake Luther"”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 35 of 40
★ FPSC
★ PPSC
★ 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
Correct Answer: Option A — > x <- 1:4 > lapply(x, runif, min = 0, max = 10)
Detailed Academic Explanation:
> x <- 1:4 > lapply(x, runif, min = 0, max = 10) is the correct answer to “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”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 36 of 40
★ FPSC
★ PPSC
★ 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)
Correct Answer: Option A — 32
Detailed Academic Explanation:
32 is the correct answer to “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)”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
. . . . . . . . function is same as lapply in R.
Correct Answer: Option C — sapply()
Detailed Academic Explanation:
sapply() is the correct answer to “. . . . . . . . function is same as lapply in R.”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What would be the value of following R expression? log(-1)
Correct Answer: Option A — Warning in log(-1): NaNs produced
Detailed Academic Explanation:
Warning in log(-1): NaNs produced is the correct answer to “What would be the value of following R expression? log(-1)”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 39 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The . . . . . . . . for R are the main feature that make it different from the original S language.
Correct Answer: Option A — scoping rules
Detailed Academic Explanation:
scoping rules is the correct answer to “The . . . . . . . . for R are the main feature that make it different from the original S language.”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following R code? > f <- function(elt) { + elt[, 1] + } > lapply(x, f)
$a [1] 1 2 $b [1] 1 2 3 is the correct answer to “What will be the output of the following R code? > f <- function(elt) { + elt[, 1] + } > lapply(x, f)”. This question is standard in competitive examination syllabi for Control Structures In R Programming.
💡Key Conceptual Anchor:Control Structures In R Programming
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡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.