Bird
0
0

Why does this script cause an infinite loop?

medium📝 Debug Q7 of 15
Bash Scripting - Loops
Why does this script cause an infinite loop?
count=1
until [ $count -gt 3 ]
do
  echo $count
done
AVariable count is never incremented inside the loop
BCondition syntax is incorrect
CMissing done keyword
DUsing -gt instead of -lt in condition
Step-by-Step Solution
Solution:
  1. Step 1: Analyze loop body

    The loop prints count but never changes its value.
  2. Step 2: Understand loop condition effect

    Since count stays 1, condition count -gt 3 never becomes true, causing infinite loop.
  3. Final Answer:

    Variable count is never incremented inside the loop -> Option A
  4. Quick Check:

    Increment loop variable to avoid infinite loop [OK]
Quick Trick: Always update loop variable inside until loop [OK]
Common Mistakes:
MISTAKES
  • Forgetting to increment variable
  • Wrong condition logic

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes