C3 Tutorial
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Foreach

  • Use foreach to iterate over any collection (array, subarray, vector or any customized type implementing the indexing operators)
  • foreach_r conversely allows iteration from back and forward.
  • Either iterate over the value: foreach (v : values) or over index + value: foreach (index, v : values)
  • Values can also be retrieved by reference by using & in front of the variable name: foreach (&v : values), this allows mutation of the element directly.