Logo

Programming-Idioms

History of Idiom 7 > diff from v110 to v111

Edit summary for version 111 by programming-idioms.org:
[C++] Revert the nonsense (see history)

Version 110

2021-06-20, 15:32:36

Version 111

2021-08-16, 21:11:54

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Variables
i,x,items
Variables
i,x,items
Extra Keywords
indices traverse traversal
Extra Keywords
indices traverse traversal
Imports
#include <iostream>
Imports
#include <iostream>
Code
for (std::size_t ix = 0; ix < items.size(); ++ix) {
  if (8 == ix)
	return true;
}
Code
for (std::size_t ix = 0; ix < items.size(); ++ix) {
  std::cout << "Item " << ix << " = " << items[ix] << std::endl;
}