c16b59191b
iteration over CharSequences. CharSequences may be mutable (e.g., StringBuilder) and therefore its contents and length can change within the loop.
19 lines
395 B
Kotlin
Vendored
19 lines
395 B
Kotlin
Vendored
// KJS_WITH_FULL_RUNTIME
|
|
// WITH_RUNTIME
|
|
import kotlin.test.*
|
|
|
|
fun box(): String {
|
|
val sb = StringBuilder("1234")
|
|
val result = StringBuilder()
|
|
var ctr = 0
|
|
for (c in sb) {
|
|
if (ctr % 2 == 0)
|
|
sb.append('x')
|
|
ctr++
|
|
result.append(c)
|
|
}
|
|
assertEquals("1234xxxx", sb.toString())
|
|
assertEquals("1234xxxx", result.toString())
|
|
|
|
return "OK"
|
|
} |