Ruby Loop MCQ

11. What is true about Until loop?

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

View Answer


12. What is the use of break statement?

A. Terminates the most External loop.
B. Terminates all loop.
C. Terminates the program.
D. Terminates the most internal loop.

View Answer


13. Which statement is used to Restarts this iteration of the most internal loop, without checking loop condition?

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

View Answer


14. What does the 1..5 indicate?

A. Exclusive range
B. Both inclusive and exclusive range
C. Inclusive range
D. None of the above

View Answer


15. Which of the following is Exit Controlled loop?

A. do..while
B. For
C. Until
D. While

View Answer


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

for i in 1...3  
  for j in 1..3
  puts j
  end
end

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

View Answer


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

i=1
for i in 6..10
puts i**2
end

A. 36 49 64 81
B. 49 64 81 100
C. 49 64 81
D. 36 49 64 81 100

View Answer


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

counter = 1
while counter < 5
  puts counter
  counter = counter + 1
end

A. Prints the number from 1 to 4
B. Prints the number from 1 to 5
C. Prints the number from 2 to 5
D. Prints the number from 2 to 4

View Answer


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

while a&&b
puts a
end

A. TRUE
B. FALSE
C. Syntax Error
D. Name Error

View Answer


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

i = 4
while i > 0 do
  print i
  i -= 1
end

A. 321
B. 3210
C. 4321
D. 43210

View Answer





Discussion


* You must be logged in to add comment.