Imam Nawawi says in his book ‘Al-Adhkaar’ p.356 that: It is forbidden for a person to say, ‘if I do so and so, I have become a Jew or I am no longer a Muslim or other similar statements.’
Any Muslim that made such statement and intends by it to leave Islam, then such a person is no longer considered a Muslim. He has automatically become an unbeliever and will be judged as an apostate.
But if he did not mean it, then he has not turn to an unbeliever. However, such person has sinned and needs to repent by admitting the sin, regret on it, make a determination never to do that again, seek for Allah’s forgiveness, and finally say the Shahadah (laa illaaha illa Allaah) – there is no deity worthy of worshipping except Allaah.