Skip to main content

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
Question 1 of 40
★ FPSC ★ PPSC

What is the keyword used to define a conditional statement in Ruby?

Question 2 of 40
★ FPSC ★ PPSC

Which of the following loops in Ruby is executed at least once?

Question 3 of 40
★ FPSC ★ PPSC

In Ruby, what does the unless keyword do?

Question 4 of 40
★ FPSC ★ PPSC

What is the purpose of the case statement in Ruby?

Question 5 of 40
★ FPSC ★ PPSC

Which loop in Ruby allows you to iterate over a collection of elements?

Question 6 of 40
★ FPSC ★ PPSC

What is the result of the expression 5 > 3 ? "Yes" : "No" in Ruby?

Question 7 of 40
★ FPSC ★ PPSC

What does the break keyword do in a loop in Ruby?

Question 8 of 40
★ FPSC ★ PPSC

Which of the following is NOT a comparison operator in Ruby?

Question 9 of 40
★ FPSC ★ PPSC

What is the purpose of the redo keyword in Ruby?

Question 10 of 40
★ FPSC ★ PPSC

What is the output of the following code snippet? x = 10 unless x > 15 puts "Hello" end

Question 11 of 40
★ FPSC ★ PPSC

What does the `next` keyword do in a loop in Ruby?

Question 12 of 40
★ FPSC ★ PPSC

In Ruby, what does the `elsif` keyword allow you to do?

Question 13 of 40
★ FPSC ★ PPSC

Which of the following is NOT a logical operator in Ruby?

Question 14 of 40
★ FPSC ★ PPSC

What is the output of the following code snippet? x = 5 while x > 0 puts x x -= 1 end

Question 15 of 40
★ FPSC ★ PPSC

What does the `retry` keyword do in Ruby?

Question 16 of 40
★ FPSC ★ PPSC

Which loop in Ruby allows you to execute code while a condition is true?

Question 17 of 40
★ FPSC ★ PPSC

What does the unless keyword do in Ruby?

Question 18 of 40
★ FPSC ★ PPSC

What is the purpose of the next keyword in a loop in Ruby?

Question 19 of 40
★ FPSC ★ PPSC

What is the output of the following code snippet? x = 1 loop do puts x x += 1 break if x > 5 end

Question 20 of 40
★ FPSC ★ PPSC

In Ruby, what is the purpose of the `case` statement when combined with `when` clauses?

Question 21 of 40
★ FPSC ★ PPSC

Which of the following is used to create a range in Ruby?

Question 22 of 40
★ FPSC ★ PPSC

What is the output of the following code snippet? for i in 1..5 print i, " " end

Question 23 of 40
★ FPSC ★ PPSC

In Ruby, what does the `break` keyword do when used within nested loops?

Question 24 of 40
★ FPSC ★ PPSC

Which of the following is NOT a valid way to exit a loop in Ruby?

Question 25 of 40
★ FPSC ★ PPSC

In Ruby, what does the `until` keyword do?

Question 26 of 40
★ FPSC ★ PPSC

What does the `retry` keyword do when used within a loop in Ruby?

Question 27 of 40
★ FPSC ★ PPSC

In Ruby, what does the `case` statement allow you to compare against?

Question 28 of 40
★ FPSC ★ PPSC

In Ruby, which of the following is NOT a valid loop construct?

Question 29 of 40
★ FPSC ★ PPSC

What is the purpose of the loop keyword in Ruby?

Question 30 of 40
★ FPSC ★ PPSC

Which of the following is used to define a block of code that executes repeatedly until a condition is met in Ruby?

Question 31 of 40
★ FPSC ★ PPSC

In Ruby, what is the purpose of the `redo` keyword?

Question 32 of 40
★ FPSC ★ PPSC

Which keyword in Ruby is used to exit a loop prematurely?

Question 33 of 40
★ FPSC ★ PPSC

In Ruby, which of the following is used to handle multiple conditions with one expression?

Question 34 of 40
★ FPSC ★ PPSC

In Ruby, what does the `else` keyword do?

Question 35 of 40
★ FPSC ★ PPSC

In Ruby, what does the `elsif` keyword do?

Question 36 of 40
★ FPSC ★ PPSC

The following syntax is correct for if conditional statement. if condition code end

Question 37 of 40
★ FPSC ★ PPSC

If expression. The expression can be of which type?

Question 38 of 40
★ FPSC ★ PPSC

What error does the if condition gives if not terminated with end statement?

Question 39 of 40
★ FPSC ★ PPSC

What is the output of the following? if 1<2 print "one is less than two" end

Question 40 of 40
★ FPSC ★ PPSC

What is the output of the code? if 11<2 print "Eleven is less than two" end print "11 is greater"

✓ 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 →