Challenge - 5 Problems
Infinite Loop Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this infinite loop script?
Consider this Bash script snippet. What will it output when run?
Bash Scripting
count=1 while true; do echo $count ((count++)) if [ $count -gt 3 ]; then break fi done
Attempts:
2 left
💡 Hint
Look at the break condition inside the loop.
✗ Incorrect
The loop prints numbers starting from 1 and increments count. When count becomes greater than 3, the break stops the loop. So it prints 1, 2, 3, and 4.
📝 Syntax
intermediate2:00remaining
Which option causes a syntax error in this infinite loop?
Identify which Bash loop snippet will cause a syntax error.
Attempts:
2 left
💡 Hint
Check the syntax of the while loop condition and keywords.
✗ Incorrect
Option B uses parentheses around true and misses a semicolon before do, which is invalid syntax in Bash loops.
🔧 Debug
advanced2:00remaining
Why does this infinite loop never stop?
Examine the script below. Why does it run forever without stopping?
Bash Scripting
i=0 while [ $i -lt 5 ] do echo $i done
Attempts:
2 left
💡 Hint
Check if the loop changes the variable controlling the condition.
✗ Incorrect
Variable i is initialized to 0 but never incremented inside the loop, so the condition [ $i -lt 5 ] is always true, causing an infinite loop.
🚀 Application
advanced2:00remaining
Which script safely runs an infinite loop that can be stopped by Ctrl+C?
Select the Bash script that runs an infinite loop printing 'Running' every second and can be stopped by pressing Ctrl+C.
Attempts:
2 left
💡 Hint
Consider which loop includes a pause and allows interruption.
✗ Incorrect
Option C runs an infinite loop with a 1-second pause, allowing the user to stop it with Ctrl+C. Option C has no pause, flooding output. Option C is valid but not the best choice here because it lacks explanation. Option C sleeps 0 seconds, effectively no pause.
🧠 Conceptual
expert2:00remaining
What is the main risk of an infinite loop without a break or exit condition in automation scripts?
Why should infinite loops without exit conditions be avoided in automation scripts?
Attempts:
2 left
💡 Hint
Think about what happens if a script never stops running.
✗ Incorrect
Infinite loops without exit conditions keep running and can use up CPU and memory, slowing down or crashing the system.