Concept Flow - Infinite loops
Start
Check condition
Condition true?
No→Exit loop
Yes
Execute loop body
Repeat check condition
An infinite loop keeps running because its condition never becomes false, so it never exits.
while true; do echo "Looping forever" done
| Step | Condition | Result | Action | Output |
|---|---|---|---|---|
| 1 | true | true | Print message | Looping forever |
| 2 | true | true | Print message | Looping forever |
| 3 | true | true | Print message | Looping forever |
| ... | ... | ... | ... | ... |
| n | true | true | Print message | Looping forever |
| Variable | Start | After 1 | After 2 | After 3 | ...final |
|---|---|---|---|---|---|
| condition | true | true | true | true | true |
Infinite loops run endlessly because their condition never becomes false. In bash, 'while true; do ... done' creates an infinite loop. No variable changes to stop the loop. Use Ctrl+C to stop infinite loops manually. Be careful to avoid infinite loops in scripts.