0
        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?

3
  • 1
    I don't understand why this doesn't work as it is. After each call of bot.send_message there is no more code and the program should continue with the next loop. Commented Dec 6, 2021 at 16:52
  • It works not how I want it to be. I want it to go for all the jobs, and without "continue" it shows me only one job even there are more that fit into the criteria. Commented Dec 6, 2021 at 17:11
  • @Matthias is correct, this should work as-is. You don't need continue. I suggest making a simple test case with print statements to help you understand the flow. At each point that you have **now... (# is better used for comments here btw), the next step in the logic is to exit the nested if statements and continue the for loop. If you are continuing to code below your **now... comments then just add an else statement to the inner if. Deeply nesting continues makes your code harder to understand in the future. Commented Dec 6, 2021 at 17:23

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.