in reply to Looping made easy...

Computer Science 101

Every loop has three features, and three features make any loop.

An initial condition. If you have a control variable, initialize it to a known value. If you have a data set you're working from, it should be populated and ready for processing. If you want a stream of data to be input, open the stream.

A test for a terminating condition. If you're using a control variable, check to see if it has reached or exceeded the final predicted value. If you have a data set or data stream, check if there are no more elements available. If so, terminate the loop.

A body of work. Unless magic were to somehow intrude, or your problem didn't require a loop in the first place, you will change the condition somehow. You will make progress. Any realized progress, in physics or code, is called 'work.' The control variable must be incremented. The current position in a data set (or the size of the remaining portion of the data set) must be moved forward. The data stream must be consumed. If none of these are done, you have an infinite loop, because your initial condition never changes to meet or exceed the desired termination conditions.


Separate from that primer, what does your input data look like, and what were you expecting for a result? We can't debug code in isolation, we can only explain the failure to reach the desired results and offer suggestions to achieve better results.

--
[ e d @ h a l l e y . c c ]