>Uses for-loops
Uses for-loops
Faster than foreach
I hope you're not in charge of any serious projects. That would be terrible.
maybe for now. v8 has been shaking up their code generator and optimizations lately with stuff like turbofan. most of the slowness in foreach proto vs c-style for is allocation of closures and other small details.
>posts meatwads
Who's retarded here
>his code is a bunch of ifs
Name something that's both more capable and more convenient.
>not using ifs for everything
They dont pay me enough to think
iterators
It's like you intentionally picked something that's neither more capable nor more convenient. Good laugh.
uh ok bud. pretty much everyone has them and uses them. only C-lets lack it.
maps
More convenient but less capable.
how
Gets messy and/or slow once you need something other than "I need to traverse a collection from the beginning to the end".
>his code is not impossible to understand with obfuscation
t. retard
>using foreach
>conditional branches
sepples
Increment elements of an array at powers of two indexes using maps. Hard mode: do it efficiently. Here's the solution using for:
for(int i=1;i
basically anything where the index is used somehow for loops are easier to deal with
Right, but for most real-world applications, the index is usually irrelevant.
There's also the fact that some languages like Java make it trivial to do parallel stream operations, which will perform way better than any kind of loop for heavy operations.
>java
>performing
>Still believing the "Java is slow" meme
Read my original point. There are more convenient or more capable options than for, but not at the same time. There's no outright replacement for it. Use whatever suits the task best, it's not like you're limited to only one kind of loop.
>Java is slow
>meme
>you
>knowledgeable of the supremacy of the jvm or useful abstractions.
to imply a "map" function is more convenient than the broad topic of "iterators" really shows what kind of complete dipshit you are.
We really need some programming certification before you're allowed to write software professionally. maybe then these smug "muh C, muh ptr" babbies would learn some language concepts.
>to imply a "map" function is more convenient
He clearly said maps, which is a series of functions which are in fact more convenient because they are more specialized. Reduce is also a map.
>not using glorious LOOP macro
baka
ok and? "map functions" don't magically "map" over collections. you still need the concept of an iterator for a map to fucking map. jesus fucking christ, die in a fucking fire.
I'd rather have my code repeat 1000 times than use a for loop
for x in {0..-1}:
while x is true:
x+=.5
x-=.5
break
continue
>splitting hairs this much
You aren't using iterators directly here so who gives a shit if they are used internally. Your next post is going to be "i in a[i] is an iterator".
>not using nested for loops with 1k+ iterations each
For loops are bad? Is this a new meme
i dont even know what that is
Anything that can't be unrolled by the compiler isn't an alternative to for.
>He doesn't know about about while-loop superiority
typical virgin
no shit? most languages offer useful abstractions so the iterator API is transparent:
e.g.
for (sometype x : collection) { ...
And the iterator is already dereferenced for you here. Foreach basically. In sepples for example you can use the iterator itself in some ways - that'd be using iterators to traverse.
unsigned int i = 1;
while (i < length) {
a[i] += 1;
i = i
Nice map.
I unroll all my loops manually.
What is for loop?
One of the primary sources of off by one errors and buffer overflows.
For loops are basically an antipattern at this point.
s:
(*(a+i))++ && (i = i
Nice map.
>using a language with for each
Nothing is iterated in my pure functional map you imperative brainlet
What is linear algebra?
I only use free range list comprehensions
Are you niggers serious?
>for most real-world applications
webdev babby who isn't aware of a world beyond JS detected
Wrong.
Most iteration doesn't give a shit about the index, just what's at that index.
The only times you need the index are if, for example, you want to update the equivalent index on another array, of something like where it's not just a plain iteration over the whole array.
>He uses less efficient statements
>index is usually irrelevant
Please don't ever touch the C family of languages
you heard the man, he's too good for anything below the level of a browser
you're one of those functional programming faggots?
Not with linked lists
please don't ever try to optimize anything
>eats fruitloops
>>index is usually irrelevant
Except that's true. The vast majority of list operations are of the form "do something with each value", "perform some transformation to each value", or some other form where the actual index doesn't matter.
In cases where index does matter, many of those might not need explicit index looping if the language provides something like Python's enum().
Situations where you legitimately need index are mostly those where you're taking a numerically-defined subset of the list (like the *=2 example) or where you need to operate behind the current index or 2+ ahead (1+ if the iterator doesn't support peeking).
wow OP it sure must look neat to define your index above your while loop and put a conditional in the first line of the loop to tell it when to stop. oh, and along with a line at the end to increment said index. well done OP, your code sure does look a lot more concise, thank god you didn't just do it in one line with a for loop
you have a set of things. imagine a big bucket full of apples. you want to check each apple and/or do something with them.
well, that's what loops are for.
for loop: the most basic one. very fast. you also have an index so to say, so you can say, writeSomethingOnApple(i) (i is the current element).
Pros:
- clean to write
- fast to write
- fast performing
Cons:
- you have to have an 80+ IQ so you don't write utter shit code
foreach: memeloop. People who spent a few days as an intern kinda believe its' the only thing you should use. In this case you don't have an index, only a "current element", so you know which Apple you are holding, but going back and forth, or saying, the previous apple, is a bit harder. It can also be slower.
Pros:
- cannot run out of bounds, you cannot say "take the next apple" while there are no apple left in the basket, thus crashing your application or just causing unexpected behavior.
Cons:
- can be slower
- harder to refer to next, previous element
tl;dr: Both are tools for the same task, and you should pick whichever suits the current task the best. People just like to complain, there is no "better" out of the two. If someone has a BSc at least, they can visualize the loop easily, see where it could go wrong, etc.
>whines about using for-loops
>recommends abstracted methods and functions that are using for-loops themselves
>muh code is prettier
javascript posters need to stop
Who can even say that generally? C++ does for(auto e:c) fine.
>he doesn't program in a functional style
>he doesnt use his language to its full capabilities
var.forEach(...)
Most maybe. But you frequently need an index. There's usually solutions for that for foreach in languages.
I haven't quite found that in JS though. But im new to JS.
>var.foreach is functional
Oh wow, please stop breathing. Functional programming can't be what you think it is if you believe it's a relevant comment here.
>not using fold
you all have terminal autism
on the bright side you're a vanguard for new ICD codes
>adds function overhead to basic iterations
OP sucks
for i in range(10):
print("xD")
i love python
pfft not using recursion.