Skip to main content

Control Structures In Ruby — Part 2 MCQs with Explanations

Practice high-yield Programming & Software Development MCQs on Control Structures In Ruby — Part 2 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 output of the given code? if 11>2 puts "Eleven is greater than two" end print "You'r right"

Question 2 of 40
★ FPSC ★ PPSC

What is the output of the given code? if 79>78 puts "True".upcase if 9>8 puts "True".reverse if 7==7 puts "equal".downcase end end end

Question 3 of 40
★ FPSC ★ PPSC

What is the output of the given code? if 79>78 puts "True".upcase if 9>8 puts "True".Upcase if 7==7 puts "equal".downcase end end end

Question 4 of 40
★ FPSC ★ PPSC

If statement inside if statement is called Nested if statements.

Question 5 of 40
★ FPSC ★ PPSC

What is the output of the given code? x=1 if x > 2 puts "x is greater than 2" elsif x <= 2 and x!=0 puts "x is 1" else puts "I can't guess the number" end

Question 6 of 40
★ FPSC ★ PPSC

It's a good habit to give two spaces between if statement and condition.

Question 7 of 40
★ FPSC ★ PPSC

What is the use of else statement?

Question 8 of 40
★ FPSC ★ PPSC

Is the following syntax correct? if conditional code... elsif conditional code.. else code end

Question 9 of 40
★ FPSC ★ PPSC

What is the output of the given code? if 1>2 puts "false" else puts "True"

Question 10 of 40
★ FPSC ★ PPSC

What is the output of the code? if 1>2 puts "false" end else puts "True" end

Question 11 of 40
★ FPSC ★ PPSC

What is the output of the code? variable=true if variable puts "true" else puts "false" end

Question 12 of 40
★ FPSC ★ PPSC

What is the output of the code? variable="true".reverse if variable puts "true" else puts "false" end

Question 13 of 40
★ FPSC ★ PPSC

What is the output of the code? variable="true".length if variable puts "true" else puts "false" end

Question 14 of 40
★ FPSC ★ PPSC

Which of the following is valid conditional statement?

Question 15 of 40
★ FPSC ★ PPSC

What is the output of given code? counter=1 if counter<=5 puts (counter) counter=counter+1 else puts(counter) counter=counter-1 end

Question 16 of 40
★ FPSC ★ PPSC

It is necessary that always if should come with else block?

Question 17 of 40
★ FPSC ★ PPSC

Which of the following is valid conditional statement in Ruby?

Question 18 of 40
★ FPSC ★ PPSC

The elsif conditional statement is written with an expression.

Question 19 of 40
★ FPSC ★ PPSC

The elsif statement can add many alternatives to if/else statements.

Question 20 of 40
★ FPSC ★ PPSC

What is the output of the given code? counter=6 if counter<=5 puts (counter) counter=counter+1 puts (counter) elsif counter>5 puts (counter) counter=2*counter puts(counter) else puts(counter) counter=counter-1 puts(counter) end

Question 21 of 40
★ FPSC ★ PPSC

What is output of the given code? counter=-3 if counter<=5 puts (counter) counter=counter+1 puts (counter) elsif counter>5 puts (counter) counter=2*counter puts(counter) end

Question 22 of 40
★ FPSC ★ PPSC

What is the output of the given code? if !true print "False" elsif !true || true print "True" end

Question 23 of 40
★ FPSC ★ PPSC

What is the output of the given code? variable = false if variable print "false" elsif !variable print "true" end

Question 24 of 40
★ FPSC ★ PPSC

What is the output of the given code? x=7 y=9 if x==y print "equal" elsif x>y print "greater" else print "less" end

Question 25 of 40
★ FPSC ★ PPSC

What is the output of the given code? a=true b=false if a && b puts "False" elsif a || b puts "True" else puts "neither true nor false" end

Question 26 of 40
★ FPSC ★ PPSC

What is the output of the given code? a=10 b=2 if a>b a=a*b puts (a) elsif a<b a=a*a+b puts (a) else a=a-b puts (a) end

Question 27 of 40
★ FPSC ★ PPSC

Syntax for unless conditional statement is unless conditional [then] code else code end

Question 28 of 40
★ FPSC ★ PPSC

What is the output of the given code? x=3 unless x>2 puts "x is less than 2" else puts "x is greater than 2" end

Question 29 of 40
★ FPSC ★ PPSC

What is the output of the given code? var = 1 print "1 -- Value is set\n" if var print "2 -- Value is set\n" unless var var = false print "3 -- Value is set\n" unless var

Question 30 of 40
★ FPSC ★ PPSC

What is the output of the given code? hungry=false unless hungry print "Not hungry" else print "Hungry" end

Question 31 of 40
★ FPSC ★ PPSC

The following syntax is also used for unless conditional statement. code unless conditional

Question 32 of 40
★ FPSC ★ PPSC

What is the output of the given code? counter=12 unless counter print counter+1 else print counter+2 end

Question 33 of 40
★ FPSC ★ PPSC

What is the output of the given code? unless true && false print "false" else print "ruby" end

Question 34 of 40
★ FPSC ★ PPSC

What is the output of the given code? print "2 is less than 3" unless 2>3

Question 35 of 40
★ FPSC ★ PPSC

What is the output of the given code? x=8 y=10 unless x>y puts "x is less than y" end unless x>y+1 puts "x is less than y+1" end

Question 36 of 40
★ FPSC ★ PPSC

What is the output of the given code? x="ruby".length y="language".length puts x,y unless x>y print "length of x is less than that of y" end

Question 37 of 40
★ FPSC ★ PPSC

What is the output of the given code? age = 5 case age when 0 .. 2 puts "baby" when 3 .. 6 puts "little child" when 7 .. 12 puts "child" when 13 .. 18 puts "youth" else puts "adult" end

Question 38 of 40
★ FPSC ★ PPSC

The following syntax is used for the ruby case statement. case expression when expression , expression ... then code ... else code end

Question 39 of 40
★ FPSC ★ PPSC

What is the output of the given code? age = 4 case age puts "baby" when 0 .. 2 puts "little child" when 3 .. 6 puts "child" when 7 .. 12 puts "youth" when 13 .. 18 puts "adult" else end

Question 40 of 40
★ FPSC ★ PPSC

What is the output of the given code? for counter in 1..5 case counter when 0 .. 2 puts counter puts "baby" when 3 .. 6 puts counter puts "little child" when 7 .. 12 puts counter puts "child" else puts counter puts "adult" end end

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