Skip to content

Instantly share code, notes, and snippets.

@pennya
Last active October 18, 2018 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pennya/1e1840da6c546c0013704a6e6bcad6f2 to your computer and use it in GitHub Desktop.
Save pennya/1e1840da6c546c0013704a6e6bcad6f2 to your computer and use it in GitHub Desktop.
#Kotlin # for 다양한 사용방법
fun forTest(list: List<String>) {
for(item in list) {
println(item)
}
for(i in 0..list.size) {
println(list[i])
}
for(i in list.indices) {
println(list[i])
}
for((i, v) in list.withIndex()) {
println("index is $i, value is $v")
}
// 100까지 포함
for(i in 1..100) {}
// 99까지 포함
for(i in 1 until 100) {}
// 단위가 2
for(i in 2..10 step 2) {}
// 1까지 숫자감소
for(i in 10 downTo 1) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment