Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

A case statement compares the expression specified by case and that specified by when using the === operator and executes the code of the when clause that matches.(a) True(b) FalseI got this question by my school teacher while I was bunking the class.The doubt is from The Case Conditional Statement topic in chapter Conditional Statements of Ruby

Answer»

Right answer is (a) True

Easy explanation: A case STATEMENT is basically the MULTIPLE if-elsif-else statements.

2.

The expression specified by the when clause is evaluated as the left operand. If no when clauses match, case executes the code of the else clause.(a) True(b) FalseThis question was addressed to me during an online interview.My enquiry is from The Case Conditional Statement in section Conditional Statements of Ruby

Answer»

The correct answer is (a) True

To explain: ELSE CLAUSE is EXECUTED only when no ‘when’ clauses MATCH.

3.

The elsif statement can add many alternatives to if/else statements.(a) True(b) FalseI had been asked this question in an interview.I want to ask this question from The Elsif Conditional Statement topic in chapter Conditional Statements of Ruby

Answer» RIGHT OPTION is (a) True

Easiest EXPLANATION: We can add many conditions between if/else STATEMENTS using elsif conditional statement.
4.

It is necessary that always if should come with else block?(a) True(b) FalseThis question was addressed to me during an online exam.Asked question is from The Else Conditional Statement in chapter Conditional Statements of Ruby

Answer»

Right OPTION is (b) False

Best EXPLANATION: Not NECESSARY, if can EXECUTE alone.

5.

The elsif conditional statement is written with an expression.(a) True(b) FalseThe question was posed to me during an internship interview.Enquiry is from The Elsif Conditional Statement in section Conditional Statements of Ruby

Answer»

The correct OPTION is (a) True

Explanation: The syntax of ELSIF conditional STATEMENT is elsif with an expression.

6.

Which of the following is valid conditional statement in Ruby?(a) elseif(b) elsif(c) else if(d) elseiffThe question was posed to me during an online interview.My doubt stems from The Elsif Conditional Statement topic in section Conditional Statements of Ruby

Answer»

The CORRECT CHOICE is (B) elsif

Best explanation: We use elsif conditional statement in RUBY.

7.

Which of the following is valid conditional statement?(a) else(b) els(c) if else(d) None of the mentionedI have been asked this question during an interview.This interesting question is from The Else Conditional Statement in section Conditional Statements of Ruby

Answer»

Correct CHOICE is (a) else

Easy EXPLANATION: Else is VALID conditional statement.

8.

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 mentionedI got this question during an online interview.This key question is from The Else Conditional Statement topic in portion Conditional Statements of Ruby

Answer» CORRECT choice is (c) When the if condition is false and if ELSE condition is true then only it will get executed

The best explanation: When the if expression gives false VALUE and the else condition is true then only it will get executed.
9.

It’s a good habit to give two spaces between if statement and condition.(a) True(b) FalseI got this question by my college director while I was bunking the class.Origin of the question is The If Conditional Statement topic in section Conditional Statements of Ruby

Answer» CORRECT answer is (a) True

To EXPLAIN I would SAY: Not necessary but good CODERS follow it.
10.

What error does the if condition gives if not terminated with end statement?(a) Syntax error(b) Unexpected end(c) Expecting keyword end(d) All of the mentionedThis question was posed to me in my homework.I'm obligated to ask this question of The If Conditional Statement topic in chapter Conditional Statements of Ruby

Answer»

Correct ANSWER is (d) All of the mentioned

Easy explanation: We will GET all the THREE errors.

11.

If statement inside if statement is called Nested if statements.(a) True(b) FalseThis question was addressed to me in an international level competition.This interesting question is from The If Conditional Statement topic in division Conditional Statements of Ruby

Answer»

The correct option is (a) True

For EXPLANATION: Nested if means STATEMENT INSIDE statement.