2019年5月21日 星期二

Kotlin學習筆記(21) 使用while迴圈

Kotlin學習筆記(21)  使用while迴圈

fun main() {
    val items = listOf("apple", "banana", "kiwifruit")
    var index = 0
    while (index < items.size) {
        println("item at $index is ${items[index]}")
        index++
    }
   
    index=1
    var sum = 0
    while (index < 100) {
        sum=sum+index
        index+=2
    }
    println("1+3+5+....99= ?")
    println("the sum is  $sum")
   
}


輸出畫面
item at 0 is apple item at 1 is banana item at 2 is kiwifruit
1+3+5+....99= ? the sum is 2500


沒有留言:

張貼留言

作業2 MQTT (Relay + DHT22) 控制 ------- 利用Node-Red

作業2 MQTT (Relay + DHT22) 控制 ------- 利用Node-Red 1) 安裝Node-Red  https://ithelp.ithome.com.tw/articles/10201795 https://www.youtube.com/watch?v...