![Kotlin for문 index 포스팅 썸네일 이미지](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FcYVntf%2FbtrwPaYXRpK%2Fxaok3vL66He86P522tuD61%2Fimg.png)
Kotlin/Syntax
Kotlin for문 index
Kotlin서 List를 사용할 때 For문을 index를 기준으로 반복하는 방법 https://play.kotlinlang.org/ 1. withIndex 사용 withIndex를 사용하면 (index, value) 쌍값을 얻을 수 있다. index와 value 2개의 값을 읽을 수 있으므로 2개의 값을 이용해야만 할 때 유용하게 사용 가능하다. 여기서 생성된 index와 value는 read only로써 값 변경은 불가능 하다. 2. indices 사용 i라는 index값을 사용하여 for문을 반복하며 기존의 변수 i를 선언 후 list의 size만큼 반복문을 돌리던 기존 방식과 유사하다. 위 withIndex와 달리 value값을 위해서는 index를 사용하여 list2를 읽어야 한다. 또한. 1번..