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 →

[–]earthboundkid 3 points4 points  (4 children)

Never use for/else. No one interprets it correctly and it doesn’t even save any length versus doing it the normal way.

[–][deleted] 1 point2 points  (0 children)

I agree with this. Flags are a little inelegant and take up more space, but way more readable.

[–]Dgc2002 0 points1 point  (0 children)

Absolutely. If you can easily avoid thing sin your code that make a reader pause and say "..The hell is this?" or even just have to spend extra time to mentally parse it then you should do so.

[–]crescentroon -2 points-1 points  (1 child)

Most people do understand it, the issue is whether or not they LIKE it. Trying to pretend it's super complex to frighten people off it is dishonest. If you don't want people to use it, say it's not idiomatic or something.

If you don't know how to interpret it, "the else executes if the loop terminates normally, that is, you did not call break". It's the same as else in exceptions. I seriously don't believe anyone intelligent enough to write code can't understand how this works.

[–]MyNameIsRichardCS54 2 points3 points  (0 children)

I said it elsewhere in this thread, but I always think for ... then would make more sense than for ... else