> For the complete documentation index, see [llms.txt](https://beesec.gitbook.io/python-zero-to-hero/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://beesec.gitbook.io/python-zero-to-hero/what-is-python/loops.md).

# Loops

Now what if we had the same name checking code from the last task, but instead of not allowing entry, we waited until the right person showed up?

How do we repeatedly ask for the persons name and check to see if their name matches?

We can do this using something called a `loop`.

`while` loops will loop until a condition is met (much like our if statements from earlier).

```python
name = ""
while name != "Jabba":
    name = input("What is your name? ")
```

Since while loops take conditionals, what happens if we assign a True value to it?

```python
while True:
    print("This loop runs!")
```

The loop runs forever, as the condition never changes.

This is quite useful for input / output where you expect to repeatedly receive input. Or perhaps you want to repeatedly do something (such as check TryHackMe for new rooms).

We can tell our loop to break using a the keyword `break`.

```python
while True:
    name = input("What is your name? ")
    if name == "Jabba":
        break
```

The `break` keyword tells Python to break out of the while loop. If we do this, our code is no longer in the `while` and will continue to run.

While loops are very good for pointers. A pointer is a variable which keeps track of where it is in a list.

![](https://652622048-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MKp3VQkiduLsLGvc09g%2Fsync%2F3380a95bb032a9e5d507cd5f1eb042324c531305.png?generation=1603986952257310\&alt=media)

```python
names = ["Skidy", "DorkStar", "Ashu", "Elf"]
pointer = 0
while pointer <= len(names):
    print(names[i])
    pointer += 1
```
