package com.zj.example.kotlin.shengshiyuan.helloworld

/**
 *
 * CreateTime: 2019/1/8  18:45
 * @author 郑炯
 */

fun main(args: Array<String>) {
    val demo = `HelloKotlin-foreach`()
    demo.test1()
}

class `HelloKotlin-foreach` {

    /**
     * 输出:
     * 1
     * 3
     * 4
     */
    fun test1(){
        val list = mutableListOf(1, 2, 3, 4)

        for (position in list.indices.reversed()) {
            if (list[position] == 2) {
                list.removeAt(position)
            }
        }

        list.forEach{
            println(it)
        }
    }

}