Bird
0
0

Which of the following best describes the purpose of a while loop in Ruby?

easy📝 Conceptual Q2 of 15
Ruby - Loops and Iteration
Which of the following best describes the purpose of a while loop in Ruby?
ATo repeat a block of code while a condition is true
BTo execute code only once
CTo define a function
DTo create a new variable
Step-by-Step Solution
Solution:
  1. Step 1: Recall the role of while loops

    A while loop repeats code as long as its condition remains true.
  2. Step 2: Compare options with this definition

    Only To repeat a block of code while a condition is true matches this behavior; others describe unrelated concepts.
  3. Final Answer:

    To repeat a block of code while a condition is true -> Option A
  4. Quick Check:

    While loop purpose = repeat while true [OK]
Quick Trick: While loops repeat code while condition true [OK]
Common Mistakes:
  • Confusing with function definition
  • Thinking it runs once only
  • Mixing with variable creation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes