3.1 For each loop #
Created Saturday 11 January 2020
- keyword is for. And not for each.
- Also called range based loops.http://www.cplusplus.com/doc/tutorial/control/
- This loop is automatic and does not require the explicit initialization of any counter variable.
- Syntax: for(data_type variable_name: collection_name)
{
}
- Ranges are sequences of elements, including arrays, containers, and any other type supporting the functions begin and end; i.e works only on collections, i.e arrays, strings or vectors.
- Range based loops usually also make use of type deduction for the type of the elements with auto.
- It does **not **work with pointers.