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. What is the use of else statement?
a) When the if condition is false then the next else condition will get executed
b) When the if condition is false then the elsif condition will get executed
c) When the if condition is false and if else condition is true then only it will get executed
d) None of the mentioned

View Answer

Answer: c [Reason:] When the if expression gives false value and the else condition is true then only it will get executed.

2. Is the following syntax correct?

if conditional 
   code...
   elsif conditional 
   code..
   else
   code
   end

a) True
b) False

View Answer

Answer: a [Reason:] All the three statements execute only when it’s true.

3. What is the output of the given code?

if 1>2
   puts "false"
   else
   puts "True"

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

View Answer

Answer: c [Reason:] End statement is always must after the completion of else statement.

Output:
Syntax error

4. What is the output of the code?

 if 1>2
   puts "false"
   end
   else
   puts "True"
   end

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

View Answer

Answer: c [Reason:] No two end statements required after if and else just one end statement is sufficient.

Output:
Syntax error

5. What is the output of the code?

variable=true
   if variable
   puts "true"
   else
   puts "false"
   end

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

View Answer

Answer: b [Reason:] The condition is satisfied hence the if block code is executed.

Output:
True

6. What is the output of the code?

 variable="true".reverse
   if variable
   puts "true"
   else
   puts "false"
   end

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

View Answer

Answer: b [Reason:] Condition is satisfied and value is not changed.

Output:
True

7. What is the output of the code?

variable=true
   if !variable
   puts "true"
   else
   puts "false"
   end

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

View Answer

Answer: a [Reason:] Condition is not satisfied so else part is executed.

Output:
False

8. What is the output of the code?

variable="true".length
   if variable
   puts "true"
   else
   puts "false"
   end

a) False
b) True
c) Syntax error
d) 4

View Answer

Answer: b [Reason:] Condition is satisfied, and it is not effected by length method.

Output:
True

9. Which of the following is valid conditional statement?
a) else
b) els
c) if else
d) None of the mentioned

View Answer

Answer: a [Reason:] Else is valid conditional statement.

10. What is the output of given code?

 counter=1
    if counter<=5
    puts (counter)
    counter=counter+1
    else 
    puts(counter)
    counter=counter-1
    end

a) 1, 2
b) 1,2,3,4,5
c) 1 2 1
d) 1
2

View Answer

Answer: d [Reason:] Value of counter is printed and then incremented.

Output:
1
2

11. What is the output of given code?

#counter=1
    if counter<=5
    puts (counter)
    counter=counter+1
    else 
    puts(counter)
    counter=counter-1
    end

a) Undefined local variable counter
b) 1,2,3,4,5
c) 1 2 1
d) 1
2

View Answer

Answer: a [Reason:] Counter value must not be commented.

Output:
Undefined local variable counter

12. It is necessary that always if should come with else block?
a) True
b) False

View Answer

Answer: b [Reason:] Not necessary, if can execute alone.

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