Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Filter by Categories
nmims post
Objective Type Set
Online MCQ Assignment
Question Solution
Solved Question
Uncategorized

1. Which of the following is valid conditional statement in Ruby?
a) elseif
b) elsif
c) else if
d) elseiff

View Answer

Answer: b [Reason:] We use elsif conditional statement in Ruby.

2. The elsif conditional statement is written with an expression.
a) True
b) False

View Answer

Answer: a [Reason:] The syntax of elsif conditional statement is elsif with an expression.

3. The elsif statement can add many alternatives to if/else statements.
a) True
b) False

View Answer

Answer: a [Reason:] We can add many conditions between if/else statements using elsif conditional statement.

4. 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

a) 5
10
b) 6
12
c) Syntax error
d) None of the mentioned

View Answer

Answer: b [Reason:] The counter value is 6 hence elsif part will get executed.

Output:
6
12

5. 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

a) -3
-2
b) -3
-6
c) Syntax error
d) None of the mentioned

View Answer

Answer: a [Reason:] As the counter value is negative the if condition is true hence the if block is executed.

Output:
-3
-2

6. What is the output of the given code?

 if !true
   print "False"
   elsif !true || true
   print "True"
   end

a) True
b) False
c) Syntax eroor
d) None of the mentioned

View Answer

Answer: a [Reason:] !true || true evaluates to true, hence elsif block gets executed.

Output:
True

7. What is the output of the given code?

variable = false
   if variable
   print "false"
   elsif !variable
   print "true" 
   end

a) False
b) True
c) Syntax error
d) None of the mentioned

View Answer

Answer: b [Reason:] !variable will evaluate to true so elsif block gets executed.

Output:
True

8. 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

a) equal
b) greater
c) less
d) none of the mentioned

View Answer

Answer: c [Reason:] As x is less than y, hence else part will evaluate to true.

Output:
less

9. 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

a) false
b) true
c) neither true nor false
d) none of the mentioned

View Answer

Answer: b [Reason:] True or false will always evaluate to true, hence the elsif block is executed.

Output:
True

10. 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

a) 20
b) 102
c) -98
d) None of the mentioned

View Answer

Answer: a [Reason:] As a>b and this condition is satisfied by if block hence the if block will execute and evaluate to 20.

Output:
20

Synopsis and Project Report

You can buy synopsis and project from distpub.com. Just visit https://distpub.com/product-category/projects/ and buy your university/institute project from distpub.com

.woocommerce-message { background-color: #98C391 !important; }