Bird
0
0

Which of the following is a correct way to start an infinite loop in bash?

easy🧠 Conceptual Q11 of 15
Bash Scripting - Loops
Which of the following is a correct way to start an infinite loop in bash?
A<code>if true; then echo Loop; fi</code>
B<code>for i in 1..10; do echo $i; done</code>
C<code>while false; do echo No; done</code>
D<code>while true; do echo Hello; done</code>
Step-by-Step Solution
Solution:
  1. Step 1: Understand infinite loop syntax

    In bash, while true runs the loop forever because the condition is always true.
  2. Step 2: Check each option

    while true; do echo Hello; done uses while true correctly. for i in 1..10; do echo $i; done loops 10 times, not infinite. if true; then echo Loop; fi is a conditional, not a loop. while false; do echo No; done never runs because condition is false.
  3. Final Answer:

    <code>while true; do echo Hello; done</code> -> Option D
  4. Quick Check:

    Infinite loop = while true [OK]
Quick Trick: Infinite loops use always-true conditions like 'while true' [OK]
Common Mistakes:
MISTAKES
  • Confusing finite loops with infinite loops
  • Using false as loop condition
  • Using if instead of while

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes