As the fairytale "Jack and the Beanstalk" opens, Jack and his mother are in dire straits: the cow, Milky-White, has stopped giving milk and Jack's mother fears they will starve. So she sends Jack to market to sell the cow. However, on his way, Jack meets an old man who trades five beans for the cow...and how does Jack count?
"Two in each hand and one in your mouth," says Jack, as sharp as a needle.
Needless to say, when Jack returns home with "magic beans," his mother is furious; she throws the beans out the window and sends Jack to bed without supper. Overnight, though, the beans grow into a stalk that reaches through the clouds. Jack climbs up and meets a giant's (or "ogre's") wife, who feeds and hides him. When her husband comes to breakfast, he thinks he smells a boy and says the famous words:
I smell the blood of an Englishman,
Be he alive, or be he dead,
I'll have his bones to grind my bread.
However, the wife dissuades her husband from believing there is a boy nearby. He takes out his gold to count it and falls asleep. Jack takes some gold home to his mother so that they can eat. The gold lasts for a while, but eventually it runs out and because they need to eat, Jack climbs the beanstalk again.
The same thing happens, though the giant's wife is suspicious that Jack may have taken the gold, but Jack allays her suspicions. The woman feeds Jack, and he hides when the giant arrives. Being assured once again by his wife that there are no boys around (for he loves to eat small boys), he takes out his hen, says, "Lay," and the hen lays a golden egg. When the giant sleeps, Jack steals the hen and escapes.
Returning home, he and his mother can now live a comfortable life.
For the first two thefts, Jack steals in order to feed his mother and himself. We can easily understand that hunger might drive him to steal from the giant. However, it seems that Jack's last visit is more for the sake of his own curiosity or a need for fun. The third time he climbs the beanstalk, depending on the version of the story you read, he eludes the giant's wife. He is not caught hiding, but takes the giant's singing harp, which makes beautiful music. Rather than escaping easily as before, this time the harp calls a warning to its master.
...the harp called out quite loud, "Master! Master!" and the ogre woke up just in time to see Jack running off with his harp.
Perhaps the original storyteller (and we don't know who that is, though some may take credit for it) was pointing out Jack's lack of a good reason for stealing: for Jack is almost caught. He runs to the beanstalk with the giant chasing closely behind. Fortunately he is able to call to his mother for an axe before he reaches the ground. Even as they watch the giant descend from the clouds, Jack chops the beanstalk down and the giant falls, "breaks his crown" and dies.
As with many fairytales, Jack and his mother live happily ever after, in this story with the hen and the singing harp. Stealing in order to survive seems to be the reason for Jack's first two thieveries, but the last seems to simply be a form of entertainment to the boy.