Actually, it wasn't intended specifically to set an example, but it did serve to deliver a message that he was not someone who was going to just go away. Alexander's father, Phillip, was murdered in 336 BC, leaving Alexander to rule in his place. Many states, including Thebes and Athens, rose up in revolt when they heard the news. Alexander responded immediately by taking a cavalry force of 3000 men to put down the revolt.
Alexander and his cavalry was able to surprise the city of Thessaly, resulting in their surrender and also resulted in the Thessalians joining Alexander's cavalry. From there he advanced on Thermopylae and Corinth, and then Athens settled for peace. While he was in Corinth, Alexander was given the title of "Hegemon", or leader, of the Greek forces against the Persians.
From here, Alexander had to move north and put down an uprising in Thrace and then Illyria before he could feel copmfortable setting off against the Persians. When he was finally able to move back into southern Greece, he found that he still had to deal with the city of Thebes.
A full year had passed since Phillip's death, and Thebes was the last place to resist accept Alexander as their leader. Although he tried several times to send embassadors requesting that the city surrender on peaceful terms, they stubbornly refused. As a result, he had no choice and had to advance on the city, leaving it totally destroyed.
To say that he intentionally destroyed Thebes to set an example would probably be obverstating things. By the time he came to Thebes, the rest of Greece had pretty much accepted his leadership. It may be true that he destroyed the city to set an example of what would happen to others who may choose to defy him, but he didn't appear to have set out with that intention.
See Alexander's Balkan Campaign to read some more information.