Logo

Programming-Idioms

  • Ada
  • Js
for (const x of items) {
	doSomething(x);
}
items.forEach((x) => {
    doSomething(x);
});
items.map(doSomething)

doSomething is a function
items.forEach(doSomething)

No anonymous function here, we pass a function directly to forEach
for (var i = 0; i<items.length; i++) {
  var x = items[i];
  doSomething(x);
}
for Item of Items loop
   Do_Something (Item);
end loop;
for (size_t i = 0; i < sizeof(items) / sizeof(items[0]); i++) {
	DoSomethingWith(&items[i]);
}

sizeof the array divided by the size of the first element computes the number of elements, often defined as macro ARRAY_SIZE

New implementation...