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.
Best Of |
Favorites & Replies |
Start a New Board |
My Fool |
BATS data provided in real-time. NYSE, NASDAQ and NYSEMKT data delayed 15 minutes.
Real-Time prices provided by BATS. Market data provided by Interactive Data.
Company fundamental data provided by Morningstar. Earnings Estimates, Analyst Ra