Bird
0
0

Why does this infinite loop script fail?

medium📝 Debug Q7 of 15
Bash Scripting - Loops
Why does this infinite loop script fail?
set -u
while true; do
  echo "Running"
  count=$((count + 1))
done
AMissing semicolon after 'do'
BMissing 'break' to stop the loop
CIncorrect arithmetic syntax
DVariable 'count' is not initialized before use
Step-by-Step Solution
Solution:
  1. Step 1: Check variable initialization

    Variable 'count' is used before being set, causing error.
  2. Step 2: Confirm syntax correctness

    Arithmetic syntax and semicolons are correct; no break needed for infinite loop.
  3. Final Answer:

    Variable 'count' is not initialized before use -> Option D
  4. Quick Check:

    Initialize variables before arithmetic [OK]
Quick Trick: Initialize variables before using in loops [OK]
Common Mistakes:
MISTAKES
  • Assuming uninitialized variables default to zero
  • Confusing missing break as error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes