当前位置:网站首页>kotlin 循环控制
kotlin 循环控制
2022-07-04 18:32:00 【AdleyTales】
fun main() {
val arr = arrayOf(1,2,3)
for ((i,item) in arr.withIndex()){
println("i:$i, item:$item")
}
/**
i:0, item:1
i:1, item:2
i:2, item:3
*/
val items = listOf("apple", "banana", "kiwi")
for (item in items) {
println(item)
}
for (i in items.indices){
println("i: $i, value:${items[i]}")
}
/**
i: 0, value:apple
i: 1, value:banana
i: 2, value:kiwi
*/
// while
var num =10
var sum: Int = 0
while (num > 0){
sum += num
num--
}
println("sum: $sum") // sum: 55
val age = 12
//var n = 5
var n = -5
do {
println("age: $age, n: $n") // age: 12, n: -5
n--
}while (n > 0)
}
边栏推荐
- Stream stream
- 数组中的第K个最大元素
- 长城证券开户安全吗 买股票怎么开户
- Have you guys ever used CDC direct Mysql to Clickhouse
- 反射(一)
- Educational Codeforces Round 22 E. Army Creation
- Pointnet/Pointnet++点云数据集处理并训练
- Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
- 求2的n次方
- C # implementation defines a set of SQL statements that can be executed across databases in the middle of SQL (detailed explanation of the case)
猜你喜欢
Summary and sorting of 8 pits of redis distributed lock

Pointnet/Pointnet++点云数据集处理并训练

如何使用Async-Awati异步任務處理代替BackgroundWorker?

Hough transform Hough transform principle

Detailed explanation of the binary processing function threshold() of opencv

在线文本行固定长度填充工具

How to use async Awati asynchronous task processing instead of backgroundworker?

大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行

Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?

Oracle with as ora-00903: invalid table name multi report error
随机推荐
socket编程demo二
在线SQL转Excel(xls/xlsx)工具
Shell 编程核心技术《二》
Niuke Xiaobai monthly race 7 I new Microsoft Office Word document
node_ Exporter deployment
Detailed explanation of the binary processing function threshold() of opencv
2014 Hefei 31st youth informatics Olympic Games (primary school group) test questions
The explain statement in MySQL queries whether SQL is indexed, and several types in extra collate and summarize
There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks
反射(一)
26. Delete the duplicate item C solution in the ordered array
测试工程师如何“攻城”(上)
有关架构设计的个人思考(本文后续不断修改更新)
Is it safe to open an account at Great Wall Securities? How to open an account when buying stocks
Bi skills - permission axis
Stream流
. Net ORM framework hisql practice - Chapter 2 - using hisql to realize menu management (add, delete, modify and check)
LeetCode 赎金信 C#解答
牛客小白月赛7 F题
Opencv functions and methods related to binary threshold processing are summarized for comparison and use