No. of Recommendations: 1
I loved those 'goto' loops! And I was good at it, too.

I once taught a computer programming class for several months with a few different groups of students. When I was introducing the subject of loops, I always opened with this story.

There is something called a Sphex wasp. The Sphex has an interesting routine it goes through when feeding its young. It will drag some food (a caterpillar, for instance) back to its nest, go inside and check on its babies, then come out and pull the caterpillar in.

This appears to be very intelligent, motherly behavior. But researchers found something interesting. If, while the Sphex is checking on the babies, you move the caterpillar away from the nest, then when it comes out it will get confused. After it finds where the caterpillar went, it will drag it back to the nest, go inside and check on the babies again, and come back out again. While it's inside, you can drag the caterpillar away yet again, and the whole thing will be repeated. The Sphex never catches on -- it always repeats all the steps including the check, forever. So it appears that the wasp is not demonstrating intelligence or learned behavior; its brain is somehow hard-wired to perform those actions.

The moral of this story is: you should always make sure that your loops are guaranteed to reach a terminating condition, or your computer will get stuck, just like a Sphex wasp.
Print the post  


What was Your Dumbest Investment?
Share it with us -- and learn from others' stories of flubs.
When Life Gives You Lemons
We all have had hardships and made poor decisions. The important thing is how we respond and grow. Read the story of a Fool who started from nothing, and looks to gain everything.
Contact Us
Contact Customer Service and other Fool departments here.
Work for Fools?
Winner of the Washingtonian great places to work, and Glassdoor #1 Company to Work For 2015! Have access to all of TMF's online and email products for FREE, and be paid for your contributions to TMF! Click the link and start your Fool career.