Ruby MCQ On Loops

This section focuses on "Loops" in Ruby. These Multiple Choice Questions (MCQ) should be practiced to improve the Ruby skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive examinations.

1. Which of the following is not a type of loop in ruby?

A. For Loop
B. Foreach Loop
C. Until Loop
D. While Loop

View Answer


2. What is true about while loop?

A. Executes code while conditional is true
B. In while loop increment is not required
C. Executes code while conditional is false
D. None of the above

View Answer


3. Which statement is used to Jumps to the next iteration of the most internal loop?

A. break
B. next
C. redo
D. retry

View Answer


4. Which statement is used to restarts the invocation of the iterator call?

A. break
B. next
C. redo
D. retry

View Answer


5. What does end represent?

A. keyword represents the ending of loop
B. keyword represents the start of loop
C. keyword represents the start and ending of loop
D. keyword represents the infinite loop

View Answer


6. What will be the output of the given code?

for num in 1...5
  puts num
end

A. 1 2 3 4
B. 1 2 3 4 5
C. 0 1 2 3 4
D. 0 1 2 3 4 5

View Answer


7. What will be the output of the given code?

for num in 1...4

   puts num*num

end

A. 0 1 4 9
B. 1 4 9 16
C. 0 1 2 3
D. 1 2 3

View Answer


8. What will be the output of the given code?

for i in 1..5 && j in 5..10
puts i+j
end

A. 6 8 10 12 14 16
B. Syntax Error
C. 6 8 10 12 14
D. Type Error

View Answer


9. What will be the output of the given code?

counter = true
while counter !=false
  puts counter
end

A. TRUE
B. FALSE
C. Syntax Error
D. Infinite Loop

View Answer


10. What will be the output of the given code?

a=1
b=1
while a&&b
puts a+b
end

A. 2
B. 2 2 2 2 2
C. Infinite Loop
D. Syntax Error

View Answer





Discussion


* You must be logged in to add comment.