0
0
Bash Scriptingscripting~10 mins

Infinite loops in Bash Scripting - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create an infinite loop using while.

Bash Scripting
while [1]; do
  echo "Looping forever"
done
Drag options to blanks, or click blank then click option'
A0
Btrue
C1
Dfalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'false' which stops the loop immediately.
Using '0' or '1' which are not valid conditions in bash.
2fill in blank
medium

Complete the code to create an infinite loop using for.

Bash Scripting
for (( [1] )); do
  echo "Looping forever"
done
Drag options to blanks, or click blank then click option'
A;; ;;
B;;;
C;;
D;; ;; ;;
Attempts:
3 left
💡 Hint
Common Mistakes
Adding extra semicolons causes syntax errors.
Trying to put a condition that eventually ends the loop.
3fill in blank
hard

Fix the error in the infinite loop condition.

Bash Scripting
while [ [1] ]; do
  echo "Looping forever"
done
Drag options to blanks, or click blank then click option'
A1 -eq 1
B1 = 1
Ctrue
D1 == 1
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' or '==' inside [ ] for numbers causes errors.
Using 'true' inside [ ] is invalid syntax.
4fill in blank
hard

Fill both blanks to create an infinite loop with a condition that always succeeds.

Bash Scripting
while [1] [2]; do
  echo "Still looping"
done
Drag options to blanks, or click blank then click option'
Atrue
Bfalse
C&&
D||
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'false' which stops the loop.
Using logical OR which may not keep the condition true.
5fill in blank
hard

Complete the code to create an infinite loop using a for loop with arithmetic syntax.

Bash Scripting
for (( ; [1];  )); do
  echo "Loop forever"
done
Drag options to blanks, or click blank then click option'
Btrue
Attempts:
3 left
💡 Hint
Common Mistakes
Putting values in init or increment that stop the loop.
Using false or invalid conditions.