All Countries ๐ Mcq University Model MCQ Single Answer ENGLISH RUBY WHILE LOOP 2025
Focused practice with instant answer feedback, progress tracking, and community notes in one consistent workspace.
Answer feedback follows the same pattern everywhere on BrainBoost.
Green means correct, red means incorrect, and your selected answer is underlined in purple.
What is the output of the given code?
counter = 1 while counter < 11 puts counter counter = counter + 1 end
counter = 1: Initializes a variablecounterwith the value 1.while counter < 11: This is the loop condition. The code inside the loop will execute as long as the value ofcounteris less than 11.puts counter: This line prints the current value ofcounterto the console.counter = counter + 1: This line increments thecounterby 1 in each iteration.
Now, let's trace the execution:
Iteration 1:
counteris 1.1 < 11is true.puts 1.counterbecomes 2.Iteration 2:
counteris 2.2 < 11is true.puts 2.counterbecomes 3....
Iteration 10:
counteris 10.10 < 11is true.puts 10.counterbecomes 11.Iteration 11:
counteris 11.11 < 11is false. The loop terminates.