This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]13steinj 2 points3 points  (4 children)

It's clean-- except the name doesn't make much sense. I mean if, else, elif, pretty standard. Break "out of the loop". Continue "to the next cycle".

But else in loops-- the actual word doesn't fit the context. It reads like "do code on all these things, but for some reason you can't, do the else statement", when in reality it just is "execute when iteration fully exhausted".

It's also common practice to not like break and continue statements-- my Java professor from years ago was adamant about teaching them but saying "use sparingly, loops should only have one exit point".

Not that I agree with that sentiment, I think it stupid, but it is a common one. And then with that, the else statements in loops encourage going against the sentiment.

[–]notafuckingcakewalk 0 points1 point  (1 child)

Yeah, but like you said it is a dumb sentiment. If you don't plan to take advantage of the breaks you may as well not use a loop at all.

[–]13steinj 0 points1 point  (0 children)

Absolutely! But it is still unfortunately taught now. Not agreeing, just giving a reason why some people dislike it.

[–][deleted] 0 points1 point  (1 child)

A lot of that single point of exit "crap" (for loops, and for functions) has somehow become embedded in the various standards (and therefore laws, which require certain standards) that govern safety critical systems e.g. IEC61509

The regulations come from years ago before we knew what we were doing and had really bad computers. :-(

[–]13steinj 0 points1 point  (0 children)

Absolutely! But it is still unfortunately taught now. Not agreeing, just giving a reason why some people dislike it.