for and while loop in c#

(update) Actually – there is one scenario where the for construct is more efficient; looping on an array. The compiler/JIT has optimisations for this scenario as long as you use arr.Length in the condition: for(int i = 0 ; i < arr.Length ; i++) { Console.WriteLine(arr[i]); // skips bounds check } In this very specific … Read more

Using for loop inside of a JSP

You concrete problem is caused because you’re mixing discouraged and old school scriptlets <% %> with its successor EL ${}. They do not share the same variable scope. The allFestivals is not available in scriptlet scope and the i is not available in EL scope. You should install JSTL (<– click the link for instructions) … Read more

Sum values from an array of key-value pairs in JavaScript

You could use the Array.reduce method: const myData = [ [‘2013-01-22’, 0], [‘2013-01-29’, 0], [‘2013-02-05’, 0], [‘2013-02-12’, 0], [‘2013-02-19’, 0], [‘2013-02-26’, 0], [‘2013-03-05’, 0], [‘2013-03-12’, 0], [‘2013-03-19’, 0], [‘2013-03-26’, 0], [‘2013-04-02’, 21], [‘2013-04-09’, 2] ]; const sum = myData .map( v => v[1] ) .reduce( (sum, current) => sum + current, 0 ); console.log(sum); See … Read more