Control Structures In Ruby — Part 1 MCQs with Explanations
Practice high-yield Programming & Software Development MCQs on Control Structures In Ruby — 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
What is the keyword used to define a conditional statement in Ruby?
Correct Answer: Option D — if
Detailed Academic Explanation:
if is the correct answer to “What is the keyword used to define a conditional statement in Ruby”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following loops in Ruby is executed at least once?
Correct Answer: Option D — do...while
Detailed Academic Explanation:
do...while is the correct answer to “Which of the following loops in Ruby is executed at least once”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Ruby, what does the unless keyword do?
Correct Answer: Option B — Executes code if condition is false
Detailed Academic Explanation:
Executes code if condition is false is the correct answer to “In Ruby, what does the unless keyword do”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the case statement in Ruby?
Correct Answer: Option B — To handle multiple conditions with one expression
Detailed Academic Explanation:
To handle multiple conditions with one expression is the correct answer to “What is the purpose of the case statement in Ruby”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which loop in Ruby allows you to iterate over a collection of elements?
Correct Answer: Option D — each
Detailed Academic Explanation:
each is the correct answer to “Which loop in Ruby allows you to iterate over a collection of elements”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the result of the expression 5 > 3 ? "Yes" : "No" in Ruby?
Correct Answer: Option A — Yes
Detailed Academic Explanation:
Yes is the correct answer to “What is the result of the expression 5 > 3 ? "Yes" : "No" in Ruby”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the break keyword do in a loop in Ruby?
Correct Answer: Option B — Exits the loop
Detailed Academic Explanation:
Exits the loop is the correct answer to “What does the break keyword do in a loop in Ruby”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is NOT a comparison operator in Ruby?
Correct Answer: Option D — ><
Detailed Academic Explanation:
>< is the correct answer to “Which of the following is NOT a comparison operator in Ruby”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the redo keyword in Ruby?
Correct Answer: Option A — Repeats the current iteration of the loop
Detailed Academic Explanation:
Repeats the current iteration of the loop is the correct answer to “What is the purpose of the redo keyword in Ruby”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code snippet? x = 10 unless x > 15 puts "Hello" end
Correct Answer: Option A — Hello
Detailed Academic Explanation:
Hello is the correct answer to “What is the output of the following code snippet? x = 10 unless x > 15 puts "Hello" end”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the `next` keyword do in a loop in Ruby?
Correct Answer: Option A — Continues to the next iteration of the loop
Detailed Academic Explanation:
Continues to the next iteration of the loop is the correct answer to “What does the `next` keyword do in a loop in Ruby”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Ruby, what does the `elsif` keyword allow you to do?
Correct Answer: Option C — Add an else-if condition to an if statement
Detailed Academic Explanation:
Add an else-if condition to an if statement is the correct answer to “In Ruby, what does the `elsif` keyword allow you to do”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is NOT a logical operator in Ruby?
Correct Answer: Option D — %%
Detailed Academic Explanation:
%% is the correct answer to “Which of the following is NOT a logical operator in Ruby”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code snippet? x = 5 while x > 0 puts x x -= 1 end
Correct Answer: Option B — 12345
Detailed Academic Explanation:
12345 is the correct answer to “What is the output of the following code snippet? x = 5 while x > 0 puts x x -= 1 end”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the `retry` keyword do in Ruby?
Correct Answer: Option C — Restarts the loop from the beginning
Detailed Academic Explanation:
Restarts the loop from the beginning is the correct answer to “What does the `retry` keyword do in Ruby”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which loop in Ruby allows you to execute code while a condition is true?
Correct Answer: Option A — while
Detailed Academic Explanation:
while is the correct answer to “Which loop in Ruby allows you to execute code while a condition is true”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the unless keyword do in Ruby?
Correct Answer: Option B — Executes code if condition is false
Detailed Academic Explanation:
Executes code if condition is false is the correct answer to “What does the unless keyword do in Ruby”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the next keyword in a loop in Ruby?
Correct Answer: Option D — Continues to the next iteration of the loop
Detailed Academic Explanation:
Continues to the next iteration of the loop is the correct answer to “What is the purpose of the next keyword in a loop in Ruby”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code snippet? x = 1 loop do puts x x += 1 break if x > 5 end
Correct Answer: Option A — 1 2 3 4 5
Detailed Academic Explanation:
1 2 3 4 5 is the correct answer to “What is the output of the following code snippet? x = 1 loop do puts x x += 1 break if x > 5 end”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Ruby, what is the purpose of the `case` statement when combined with `when` clauses?
Correct Answer: Option A — To define a block of code that executes when a condition is met
Detailed Academic Explanation:
To define a block of code that executes when a condition is met is the correct answer to “In Ruby, what is the purpose of the `case` statement when combined with `when` clauses”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is used to create a range in Ruby?
Correct Answer: Option D — .. or ...
Detailed Academic Explanation:
.. or ... is the correct answer to “Which of the following is used to create a range in Ruby”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following code snippet? for i in 1..5 print i, " " end
Correct Answer: Option A — 1 2 3 4 5
Detailed Academic Explanation:
1 2 3 4 5 is the correct answer to “What is the output of the following code snippet? for i in 1..5 print i, " " end”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Ruby, what does the `break` keyword do when used within nested loops?
Correct Answer: Option A — Exits only the inner loop
Detailed Academic Explanation:
Exits only the inner loop is the correct answer to “In Ruby, what does the `break` keyword do when used within nested loops”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is NOT a valid way to exit a loop in Ruby?
Correct Answer: Option B — continue
Detailed Academic Explanation:
continue is the correct answer to “Which of the following is NOT a valid way to exit a loop in Ruby”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Ruby, what does the `until` keyword do?
Correct Answer: Option B — Executes code if condition is false
Detailed Academic Explanation:
Executes code if condition is false is the correct answer to “In Ruby, what does the `until` keyword do”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What does the `retry` keyword do when used within a loop in Ruby?
Correct Answer: Option B — Restarts the loop from the beginning
Detailed Academic Explanation:
Restarts the loop from the beginning is the correct answer to “What does the `retry` keyword do when used within a loop in Ruby”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Ruby, what does the `case` statement allow you to compare against?
Correct Answer: Option D — All of the above
Detailed Academic Explanation:
All of the above is the correct answer to “In Ruby, what does the `case` statement allow you to compare against”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Ruby, which of the following is NOT a valid loop construct?
Correct Answer: Option C — dowhile
Detailed Academic Explanation:
dowhile is the correct answer to “In Ruby, which of the following is NOT a valid loop construct”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the loop keyword in Ruby?
Correct Answer: Option B — To create an infinite loop
Detailed Academic Explanation:
To create an infinite loop is the correct answer to “What is the purpose of the loop keyword in Ruby”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is used to define a block of code that executes repeatedly until a condition is met in Ruby?
Correct Answer: Option C — loop
Detailed Academic Explanation:
loop is the correct answer to “Which of the following is used to define a block of code that executes repeatedly until a condition is met in Ruby”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Ruby, what is the purpose of the `redo` keyword?
Correct Answer: Option A — Repeats the current iteration of the loop
Detailed Academic Explanation:
Repeats the current iteration of the loop is the correct answer to “In Ruby, what is the purpose of the `redo` keyword”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which keyword in Ruby is used to exit a loop prematurely?
Correct Answer: Option B — break
Detailed Academic Explanation:
break is the correct answer to “Which keyword in Ruby is used to exit a loop prematurely”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Ruby, which of the following is used to handle multiple conditions with one expression?
Correct Answer: Option C — case
Detailed Academic Explanation:
case is the correct answer to “In Ruby, which of the following is used to handle multiple conditions with one expression”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Ruby, what does the `else` keyword do?
Correct Answer: Option C — Specifies the code block to execute if no other conditions are met
Detailed Academic Explanation:
Specifies the code block to execute if no other conditions are met is the correct answer to “In Ruby, what does the `else` keyword do”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Ruby, what does the `elsif` keyword do?
Correct Answer: Option A — Specifies the code block to execute if a condition is true
Detailed Academic Explanation:
Specifies the code block to execute if a condition is true is the correct answer to “In Ruby, what does the `elsif` keyword do”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 36 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The following syntax is correct for if conditional statement. if condition code end
Correct Answer: Option A — True
Detailed Academic Explanation:
True is the correct answer to “The following syntax is correct for if conditional statement. if condition code end”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
If expression. The expression can be of which type?
Correct Answer: Option D — All of the mentioned
Detailed Academic Explanation:
All of the mentioned is the correct answer to “If expression. The expression can be of which type”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What error does the if condition gives if not terminated with end statement?
Correct Answer: Option D — All of the mentioned
Detailed Academic Explanation:
All of the mentioned is the correct answer to “What error does the if condition gives if not terminated with end statement”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 39 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the following? if 1<2 print "one is less than two" end
Correct Answer: Option A — One is less than two
Detailed Academic Explanation:
One is less than two is the correct answer to “What is the output of the following? if 1<2 print "one is less than two" end”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the code? if 11<2 print "Eleven is less than two" end print "11 is greater"
Correct Answer: Option A — 11 is greater
Detailed Academic Explanation:
11 is greater is the correct answer to “What is the output of the code? if 11<2 print "Eleven is less than two" end print "11 is greater"”. This question is standard in competitive examination syllabi for Control Structures In Ruby.
💡Key Conceptual Anchor:Control Structures In Ruby
✓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.