Why do I remember reading that for loops should be avoided in programming? Am I remember wrong? Why the hell would you avoid for loops? What am I supposed to use instead?
Why do I remember reading that for loops should be avoided in programming? Am I remember wrong...
You probably read some angry NEET Haskell fag rant on Sup Forums.
>What should I use instead
goto
Matrix algebra
Maybe what was meant was that you should use foreach instead of for, when you loop through lists etc.?
>Am I remember wrong?
Whoops typo, I'm not Rajesh guys.
>What am I supposed to use instead?
map, filter, each, etc. with an associated closure
You should avoid nested for loops when dealing with large inputs since you'll have O(n^2) behaviour.
That's true for anything that loops through n.
And for doesn't have to loop through n
old and busted
for(var i = 0; i < 10; i++) {
console.log(i);
}
new hotness
_.each(_.range(10), function(i) {
console.log(i);
});
American education everyone.
This answer just shows how little you understand of what you're saying.
Right, I thought maybe OP is conflating it with that.
Similar here. Used numpy and always heard from profs to avoid loops if possible because the provided (vectorized) functions are almost always better.
Also, I think in embedded systems you avoid infinite loops.
Also I've come across some guidelines that say to avoid explicit nested loops. You should ideally factor out the inner loop into a function.
Infinite loops are used all the time in embedded.
dude algos lol
even newer hotness
_.range(10).map(console.log);
>muh americans
Insecure butthurt Eurotrash with inferiority complex everyone.
hello fefe you fat fuck
You can go fully vectorized with numpy, but good luck maintaining the code. Ideally you should use normal programming as default, and vectorize really intensive stuff when absolutely needed
babby's first O notation
There isn't a valid reason to avoid loops. But chaining maps, filters, reduces etc give you much sexier looking code.
If you're dealing with some 10 loop iterations, go for it.
If you have hundreds or thousands of datapoints, and even more so if you want to have multiple loops, you should do array math instead since languages are optimized for arrays.
Try both options yourself to see the difference.
what did he mean by this?
nice numbers
If you aren't good enough at LA for vectorization to come naturally you probably shouldn't be coding anything where the performance difference matters
Uncaught ReferenceError: _ is not defined
at :1:1