4 ms·
I have one to bring up "for loops". I think they are infinitely worse than while loops. (I ran into this specifically with Pandas dataframes/series) You save
by qualityonly 6y ago
I have one to bring up "for loops".
I think they are infinitely worse than while loops. (I ran into this specifically with Pandas dataframes/series)
You save 1 or 2 lines and have ambiguity on wherever "each" is.
Maybe static typing solves this, but I've decided I hate syntax sugar and dynamic typing.
- alisonkisk 6y agoYou might have a good point, but you haven't given enough code to expresss your idea. What is "each" ?
- cgriswald 6y agoAlthough for loops might all be while loops at heart, I think the distinction is more than just syntactic. Properly used, the use of a for loop conveys particular information: the code block is intended to run a set number of times or over a particular group of objects. This allows while loops in general to be used specifically for running the code block an indefinite number of times until the criteria is met. (Certainly both types of loops can be misused and abused.) It also splits apart two different kinds of criteria. "Has this run ten times" is a different sort of question than "is the error within the given margin" or "does the temperature now read 60 degrees". (At least, if you're intentionally running the thing 10 times. If it's running incidentally so you don't even know if it will run 10 times then it can be the same sort of question, but in that case I'd argue you should use a while loop….) > You save 1 or 2 lines and have ambiguity on wherever "each" is. Like the sibling poster, I'm not certain what you mean by this.