Performance issue for vector::size() in a loop in C++

In theory, it is called each time, since a for loop: for(initialization; condition; increment) body; is expanded to something like { initialization; while(condition) { body; increment; } } (notice the curly braces, because initialization is already in an inner scope) In practice, if the compiler understands that a piece of your condition is invariant through … Read more

forEach loop through two arrays at the same time in javascript

Use the second parameter forEach accepts instead, which will be the current index you’re iterating over: n = [1,2,3,5,7,8,9,11,12,13,14,16,17,18,20,21,22]; n.forEach((element, index) => { console.log(element, index); }); If you have two separate arrays to begin with, in each iteration, access the [index] property of the other array: var n = [1, 2, 3, 5, 7, 8, … Read more

Should I use std::for_each?

There is an advantage to using std::for_each instead of an old school for loop (or even the newfangled C++0x range-for loop): you can look at the first word of the statement and you know exactly what the statement does. When you see the for_each, you know that the operation in the lambda is performed exactly … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)