下面我们来通过代码熟悉一下Kotlin的循环语句
val chararr:CharArray= charArrayOf('a','s','d','f','g')
fun main(args: Array<String>) {
for (char in chararr){
println(char)
}
for ((index,vale)in chararr.withIndex()){
println("$index - > $vale")
}
for (indexva in chararr.withIndex()){
println("${indexva.index} --> ${indexva.value}")
}
val list= MyIntList()
list.add(1)
list.add(2)
list.add(3)
list.add(4)
list.add(5)
for (li in list){
println(li)
}
}
class MyIterator(val inte:Iterator<Int>){
operator fun next():Int{
return inte.next()
}
operator fun hasNext():Boolean{
return inte.hasNext()
}
}
class MyIntList{
private val list=ArrayList<Int>()
fun add(int:Int){
list.add(int)
}
fun remove(int:Int){
list.remove(int)
}
operator fun iterator():MyIterator{
return MyIterator(list.iterator())
}
}
这段是简单的循环代码,希望大家能喜欢,继续关注我的博客Kotlin继续学习,将会从零基础到整个Demo的完善。谢谢大家支持。也可以关注下面二维码。
![这里写图片描述](https://img-blog.csdn.net/20171201111649139?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZ3d6MTAyNTAzMzA=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)