Did you know else can be used after while loop in python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Did you know else can be used after while loop in python?

https://code.sololearn.com/cyPFLPNThB00/?ref=app

5th Dec 2022, 5:44 PM
Manas Ranjan Adha
7 Answers
+ 5
we can also use *else* : > with a *for* loop > with *try... except...*
5th Dec 2022, 7:33 PM
Lothar
Lothar - avatar
+ 1
Yes! You can use it insted of using a flag.
5th Dec 2022, 5:58 PM
Per Bratthammar
Per Bratthammar - avatar
+ 1
Yes. It will output anyway. When the while end
5th Dec 2022, 6:41 PM
GERMAN Kashanskiy
GERMAN Kashanskiy - avatar
0
GERMAN Kashanskiy I don’t know what you mean with ’anyway’, but if you break the loop with ’break’ or ’return’, what inside ’else’ will not run.
5th Dec 2022, 7:37 PM
Per Bratthammar
Per Bratthammar - avatar
0
Per Bratthammar In his code else will be executed anyway. And this will happen after executing while
5th Dec 2022, 7:40 PM
GERMAN Kashanskiy
GERMAN Kashanskiy - avatar
0
GERMAN Kashanskiy I see. I understand what you mean now.
5th Dec 2022, 7:43 PM
Per Bratthammar
Per Bratthammar - avatar
0
Manas Ranjan Adha Here’s an example using while loop with flag resp else: https://code.sololearn.com/cvkH6fIponk2/?ref=app
5th Dec 2022, 8:37 PM
Per Bratthammar
Per Bratthammar - avatar