전체 코드

아래 예제는 list 기준이며 arraylist 등 다른 자료형에서도 사용 가능하다.

var testList = listOf(10,20,30,40,50)
for((index, value) in testList.withIndex()){
    print("${index}, ${value}\n")
}

 

깃허브

https://github.com/HydroponicGlass/2022_Example_Kotlin/tree/main/For