# Infinite Loop

> A loop that never ends. Usually a bug, and the program seems to freeze.

**Field:** Software Development  
**Category:** Programming Concepts  
**Also known as:** Endless Loop

## Think of it like

Think of it like a dog chasing its own tail. It goes round and round and never gets anywhere.

## Definition

An infinite loop is a loop that never stops. Usually it is a bug: the test that should end it never turns false. The program seems to freeze while the computer works as hard as it can. Sometimes a loop is meant to run forever, like a game waiting for key presses. In that case something else, like a break, is the way out.

## Example

Jack writes while n > 0 but forgets n = n - 1. The program prints 3 over and over until he presses Ctrl+C.

## Example code

```python
n = 3
while n > 0:
    print(n)   # n never changes
# 3, 3, 3, 3 ... until Ctrl+C
```

Nothing changes n, so the test is true forever.

## Why it matters

A stuck program wastes power and makes people think it crashed. Knowing the cause makes it quick to fix.

## Common mistake

Thinking the computer is just slow. If nothing happens for long, check for a loop whose test never changes.

## Three principles

- **No way out.** The end test never turns false.
- **Looks frozen.** The program works hard but shows nothing.
- **Sometimes on purpose.** A game loop runs until you quit.

## Related terms

- [Loop](https://learn.benibix.com/term/development/loop)
- [While Loop](https://learn.benibix.com/term/development/while-loop)
- [Break Statement](https://learn.benibix.com/term/development/break-statement)
- [Bug](https://learn.benibix.com/term/development/bug)

## Taught in

- [For and While Loops](https://learn.benibix.com/learn/development-concepts/for-and-while-loops): Programming Basics, 11/18

---

Source: https://learn.benibix.com/term/development/infinite-loop
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
