On The Origin of Species by Charles Darwin Chapter 8 Page 4

As in repeating a well-known song, so in instincts, one action follows another by a sort of rhythm; if a person be interrupted in a song, or in repeating anything by rote, he is generally forced to go back to recover the habitual train of thought: so P.

Huber found it was with a caterpillar, which makes a very complicated hammock; for if he took a caterpillar which had completed its hammock up to, say, the sixth stage of construction, and put it into a hammock completed up only to the third stage, the caterpillar simply re-performed the fourth, fifth, and sixth stages of construction. If, however, a caterpillar were taken out of a hammock made up, for instance, to the third stage, and were put into one finished up to the sixth stage, so that much of its work was already done for it, far from deriving any benefit from