A study carried out at the University of Chicago surmised that people whistle to distract the brain from overload. This suggestion came from a study into the phenomenon of choking carried out by a leading Psychologist Dr Sian Beilock.
Whistling works similarly to singing by calming down the brain, which can sabotage performance by focusing too much on the task at hand. By spontaneously whistling, the brain is distracted. Casual whistling, for the pleasure of hearing a specific tune, is more an art form of whistling. Another form of whistling could be for a command, such as instructing sheep dogs to perform certain tasks.