0

Anyone can explain the logic of the last "else"?

here is a code which will print "great!" after 3 times of "yes!", but I don't understand the logic of the last "else". How can it happened when theres no "if" on the outside. Thanks! https://code.sololearn.com/cbchbECGyqCB/?ref=app

22nd Oct 2020, 12:46 PM
Joe Ma
Joe Ma - avatar
3 Answers
+ 4
If the loop is completed successfully then else run in for else statement and if the loop is braked then else never runs
22nd Oct 2020, 12:59 PM
Ayush Kumar
Ayush Kumar - avatar
0
"The else block just after for/while is executed only when the loop is NOT terminated by a break statement." great, I understand now, thank you so much🙏
22nd Oct 2020, 1:31 PM
Joe Ma
Joe Ma - avatar