0

Why this break statement not work?

In this code break statement not in loop why? And when it is in loop i want to print only "yes" but why it prints "None" also? https://code.sololearn.com/cee5TGEAD6Ef/?ref=app

3rd Jun 2021, 10:08 AM
Aayush Jat
Aayush Jat - avatar
3 Respuestas
+ 2
Aayush Jat If you haven't a loop you can't use "break" or "continue" keywords. Instead you can use "pass" (or "return" if you are inside a function) to have in part the same behaviour Try with def search(text,word): if word in text: return "yes" return def search(text,word): if word in text: return "yes" def search(text,word): if word in text: return "yes" else: pass def search(text,word): if word in text: print("yes") and so on...
3rd Jun 2021, 10:23 AM
David Ordás
David Ordás - avatar
+ 1
Where is the loop in your code ?
3rd Jun 2021, 10:10 AM
Arsenic
Arsenic - avatar
+ 1
None is printed as it is the return value of your function, and you print the result of its call in addition to printing 'yes' inside the function ^^ break only work in loop and if line is reached (inside an if..else statement, it depend of the condition where it is ;P
3rd Jun 2021, 10:14 AM
visph
visph - avatar