# Help: Que Manager

**URL:** <https://discourse.codecombat.com/t/help-que-manager/27023>\
**Category:** Level Help\
**Created:** [January 26, 2021, 5:19pm UTC](https://discourse.codecombat.com/t/help-que-manager/27023 "2021-01-26T17:19:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dragonlouis](https://avatars.discourse-cdn.com/v4/letter/d/7cd45c/32.png) [@Dragonlouis](https://discourse.codecombat.com/u/Dragonlouis)\
**Post date:** [January 26, 2021, 5:19pm UTC](https://discourse.codecombat.com/t/help-que-manager/27023/1 "2021-01-26T17:19:48Z")

</div>

```python

# Manage the queue without mistakes.
# Useful string constants.
PHRASE_IN = " in"
PHRASE_OUT = " out"
IDLE = "idle"
# The list of workers.
workers = hero.findByType("peasant", hero.findFriends())
# Use this array to control the worker queue.
queue = []
workerIndex = 0
while True:
    # Iterate through all the workers:
    while workerIndex < len(workers):
        worker = workers[workerIndex]
        # If the worker's "status" property is "idle":
        if worker.status is "idle":
            # Say the worker's name and the string " in":
            hero.say(worker + " in")
            # Add the worker to the end of the queue:
            workerIndex += 1
        item = hero.findNearestItem()
        # If the item exists and the queue isn't empty:
    if item:
        # Say the name of the first worker in the queue
        # with the string " out":
        hero.say(worker + " out")
        # Remove (shift) the first worker from the queue:
        workerIndex -= 1

```

Yep, that’s my code.

---

<div class="post-metadata">

**Author:** ![Dragonlouis](https://avatars.discourse-cdn.com/v4/letter/d/7cd45c/32.png) [@Dragonlouis](https://discourse.codecombat.com/u/Dragonlouis)\
**Post date:** [January 26, 2021, 5:20pm UTC](https://discourse.codecombat.com/t/help-que-manager/27023/2 "2021-01-26T17:20:21Z")

</div>

Probably the last line. Plz explain…

---

<div class="post-metadata">

**Author:** ![abc](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@abc](https://discourse.codecombat.com/u/abc)\
**Post date:** [January 26, 2021, 5:23pm UTC](https://discourse.codecombat.com/t/help-que-manager/27023/3 "2021-01-26T17:23:50Z")

</div>

You have to check if there is an item and if the length of the queue is greater than zero, so that you know that there is an item, and the queue is not empty.

---

<div class="post-metadata">

**Author:** ![Dragonlouis](https://avatars.discourse-cdn.com/v4/letter/d/7cd45c/32.png) [@Dragonlouis](https://discourse.codecombat.com/u/Dragonlouis)\
**Post date:** [January 26, 2021, 5:24pm UTC](https://discourse.codecombat.com/t/help-que-manager/27023/4 "2021-01-26T17:24:38Z")

</div>

So

```python
if item and workerIndex > 0

```

?

---

<div class="post-metadata">

**Author:** ![abc](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@abc](https://discourse.codecombat.com/u/abc)\
**Post date:** [January 26, 2021, 5:25pm UTC](https://discourse.codecombat.com/t/help-que-manager/27023/5 "2021-01-26T17:25:54Z")

</div>

You have to check the length of the queue. Check it with:

```python
len(queue) >0

```

---

<div class="post-metadata">

**Author:** ![abc](https://avatars.discourse-cdn.com/v4/letter/a/2bfe46/32.png) [@abc](https://discourse.codecombat.com/u/abc)\
**Post date:** [January 26, 2021, 5:27pm UTC](https://discourse.codecombat.com/t/help-que-manager/27023/6 "2021-01-26T17:27:30Z")

</div>

> [@Dragonlouis](#):
>
> ```python
> if worker.status is "idle":
> # Say the worker's name and the string " in":
> hero.say(worker + " in")
> # Add the worker to the end of the queue:
> workerIndex += 1
> 
> ```

You need to append the worker into the queue. And later, you need to remove the worker from the queue.

@Dragonlouis, the reason you get an infinite loop is because your code is not correct.
