πŸ“Š Ruby
Q. What will be the output of the given code?
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
πŸ’¬ Discuss
βœ… Correct Answer: (A) Prints the number from 1 to 4

Explanation: Counter value is initialized to 1 and it keeps on looping till the counter is less than 5.

Explanation by: Vinay Kumar
Counter value is initialized to 1 and it keeps on looping till the counter is less than 5.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
218
Total Visits
πŸ“½οΈ
3 y ago
Published
πŸŽ–οΈ
Vinay Kumar
Publisher
πŸ“ˆ
90%
Success Rate