+ 5
Did you know else can be used after while loop in python?
7 odpowiedzi
+ 5
we can also use *else* :
> with a *for* loop
> with *try... except...*
+ 1
Yes! You can use it insted of using a flag.
+ 1
Yes. It will output anyway. When the while end
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.
0
Per Bratthammar In his code else will be executed anyway. And this will happen after executing while
0
GERMAN Kashanskiy
I see. I understand what you mean now.
0
Manas Ranjan Adha
Here’s an example using while loop with flag resp else:
https://code.sololearn.com/cvkH6fIponk2/?ref=app