[SOLVED] How to stop IT loop in FOR loop without stopping the FOR loop

Issue

        for job in jobs:
            if int(dpr) <= int(user.dpr):
                if str(user.gender) == 'male:
                    if str(orpi) == 'yes':
                        if int(profil) >= int(user.profil):
                            bot.send_message(message.chat.id, str(name)
                        **now i want to exit the "if's" and go to next "job in for loop**
                else:
                    if int(profil) <= int(user.profil):
                            bot.send_message(message.chat.id, str(name)
                        **now i want to exit the "if's" and go to next "job in for loop**
            else:
                if str(orpi) == 'yes':
                    if int(profil_fem) >= int(user.profil):
                            bot.send_message(message.chat.id, str(name)
                        **now i want to exit the "if's" and go to next "job in for loop**
                else:
                    if int(profil_fem) >= int(user.profil):
                            bot.send_message(message.chat.id, str(name)
                        **now i want to exit the "if's" and go to next "job in for loop**

Hello, I want to make "now i want to exit the "if’s" and go to the next "job in for loop" in the code, return to the for loop (job in jobs), and process to the next job. Is there any command for it?

Solution

You can use the continue keyword.
It allows you to ignore everything that comes next and go to the start of the loop.
For example in this case:

for i in (0, 1, 2):
   print(i)
   continue
   print("This won't get executed")

The line after the continue will never run.

Answered By – CozyCode

Answer Checked By – Katrina (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *