Kotlin 에서 루프 밖으로 변수를 만드는 방법

코드 예제

3
0

N

var bubbles = 0
while (bubbles < 50) {
    bubbles++
}
println("$bubbles bubbles in the water\n")

do {
    bubbles--
} while (bubbles > 50)
println("$bubbles bubbles in the water\n")

repeat(2) {
     println("A fish is swimming")
}
-> 50 bubbles in the water
49 bubbles in the water
A fish is swimmingA fish is swimming
2
0

N

val school = arrayOf("shark", "salmon", "minnow")
for (element in school) {
    print(element + " ")
}
-> shark salmon minnow

for ((index, element) in school.withIndex()) {
    println("Item at $index is $element\n")
}
-> Item at 0 is shark
Item at 1 is salmon
Item at 2 is minnow

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................