> For the complete documentation index, see [llms.txt](https://beesec.gitbook.io/algorithms/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/algorithms/strings/counters.md).

# Counters

Here's another common pattern you may see.

```python
counter = 0
for i in n: # n is a list of items
    if condition(i):
        counter += 1
    else:
        counter -= 1
```

We have a single counter and we increment it / decrement it based on a condition.&#x20;

We keep a counter and we perform things based on this counter.

Another example is:

```python
counter = 0
while counter < len(s):
    if condition(s[counter]):
        counter += 1
```
