# Why doesn't my for loop break?

**URL:** <https://forum.freecodecamp.org/t/why-doesnt-my-for-loop-break/321379>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [October 12, 2019, 11:48pm UTC](https://forum.freecodecamp.org/t/why-doesnt-my-for-loop-break/321379 "2019-10-12T23:48:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![eoja](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/eoja/32/135387_2.png) [@eoja](https://forum.freecodecamp.org/u/eoja)\
**Post date:** [October 12, 2019, 11:48pm UTC](https://forum.freecodecamp.org/t/why-doesnt-my-for-loop-break/321379/1 "2019-10-12T23:48:47Z")

</div>

Why doesn’t my loop break when `parcels.lenght === 0` ?

```auto
function completeRoute(start) { 
  let at = start;
  pickUpParcels(at);
   
  for (let turns = 0; ; turns++) {
    console.log("turns = " + turns);
    console.log("pickedUp length for loop " + pickedUp.lenght);
    console.log("parcels length for loop " + parcels.length);
    if (parcels.lenght === 0) {
      console.log(`Delivered in ${turns} turns`);
      break;
    }  
    console.log("dest lenght = " + destination.length);
    if (destination.length === 0) getDestination();
    //console.log("destination " + destination);
    getRoute(at, destination[0]);
    console.log("route " + destination[0]);
    move(at, destination[0]);
    at = destination[0]
    destination.shift();
  }
}
completeRoute("Post Office");

```

As you can see `parcels.lenght` hits zero but the loop continues.

 ![28%20PM](https://global.discourse-cdn.com/freecodecamp/original/3X/7/3/73e220885ecfb61bd00d4b4fcb8b8be5504ca927.png)

The full code on [GitHub](https://github.com/eoja82/Parcel-Delivery-Robot/blob/master/index.html).

Secondary question, why is `pickedUp.length` undefined within `function completeRoute` when it is not undefined elsewhere in the code?

---

<div class="post-metadata">

**Author:** ![kevcomedia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevcomedia/32/125737_2.png) [@kevcomedia](https://forum.freecodecamp.org/u/kevcomedia)\
**Post date:** [October 12, 2019, 11:58pm UTC](https://forum.freecodecamp.org/t/why-doesnt-my-for-loop-break/321379/2 "2019-10-12T23:58:25Z")

</div>

You misspelled `length` in quite a few places

---

<div class="post-metadata">

**Author:** ![eoja](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/eoja/32/135387_2.png) [@eoja](https://forum.freecodecamp.org/u/eoja)\
**Post date:** [October 13, 2019, 12:04am UTC](https://forum.freecodecamp.org/t/why-doesnt-my-for-loop-break/321379/3 "2019-10-13T00:04:55Z")

</div>

Thanks, embarrassed, I thought emmet in VS Code had my back on that. But I must have fully typed it out. Good news I guess is the code logic was right. Have to be more careful in the future.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 25, 2021, 11:57am UTC](https://forum.freecodecamp.org/t/why-doesnt-my-for-loop-break/321379/4 "2021-01-25T11:57:53Z")

</div>

Closed on January 25, 2021, 11:57am UTC


