Paul recalls that our fathers in Israel were all under the cloud, all passed through the sea and all were baptized into Moses. All ate the same spiritual food and drank the same spiritual drink, from the spiritual rock that followed them, and the rock was Christ. Yet with most of them God was not pleased, and they were struck down in the wilderness.
These things happened as examples so that we would not desire evil. Do not be idolaters: the people sat down to eat and drink and rose up to play. Let us not indulge in sexual immorality: twenty-three thousand fell in a single day. Let us not put Christ to the test, as some did and were destroyed by serpents. Do not grumble, as some did and were destroyed by the destroyer. Let anyone who thinks he stands take heed lest he fall. No temptation has overtaken you that is not common to people, and God is faithful: with the temptation he will also provide the way of escape, that you may be able to endure it.
So Paul commands them to flee from idolatry. The cup of blessing and the bread that we break are a participation in the blood and the body of Christ, and since we are many we are one body. What pagans sacrifice they offer to demons, and one cannot drink the cup of the Lord and the cup of demons.
Paul returns to freedom: all things are lawful, but not all build up. They may eat what is sold in the meat market without asking, and what an unbelieving host sets before them; but if someone says it was offered in sacrifice, they should not eat it, for the sake of conscience. Whether they eat or drink, they should do all to the glory of God, giving no offense to anyone.