Surah An-Nisa Verse 140: Not Sitting With Immoral People
The verse is in the context that the people of Makkah were invited to Islam and they used to ridicule oneness of God and the hereafter. The Muslims were asked not to keep sitting with them when they are in that state of denial and fun. When that state passed, You may join them. If you find an company where you can escape a sin, you may dissociate yourself from them for the moment.