示例:

    1. int list[5] = {1,2,3,4,5};
    2. for (int item : list) {
    3. //...
    4. }

    如果需要修改数组元素,使用 & 引用:

    1. for (int &item : list) {
    2. //...
    3. }

    还可以结合使用初始化列表:

    1. for (int x : {3,4,5,6}) {
    2. //...
    3. }