0

The following is my code for pickup. If I am not within 15 metres of a person then it is fine. If however I am, my session goes into an infinite loop. I can't see why, could someone please give me a hand?

function pickup()
{
    if(seatsleft > 0)
    {
        for (i = 0; i < PASSENGERS.length; i++)
        {
            var lat = //calc lat;
            var lng = //calc lng;

            console.log(lat); // self check
            console.log(lng); // self check

            var dist = // calc distance of people from shuttle

            if(dist <= 15.0)
            {                        
                var nextseat = null;

                for (i = 0; i < shuttle.seats; i++)
                {
                    if (shuttle.seats[i] == null)
                    {
                        nextseat = i;
                    }
                }

                shuttle.seats[nextseat] = [{
                name: PASSENGERS[i].name,
                house: PASSENGERS[i].house
                }];

                seatsleft--;

                var features = earth.getFeatures();
                features.removeChild(PASSENGERS[i].placemark);

                PASSENGERS[i].marker.setMap(null);
            }
            else
            {
                $("#announcements").html("No Passengers nearby");
            }    
        }
        chart();
    }
    else
    {
        $("#announcements").html("The Bus is Full");
    }
}
-1

The infinite loop is caused due to the fact that I have redefined 'i' inside the loop. My update to chart() is not working though so I still need to work that out.

1
  • Please don't use the Answer button to add new details. Instead, please edit the original question with the new information. – Tim Mar 20 '15 at 12:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .