当前位置:网站首页>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)
}
边栏推荐
- In flinksql, in addition to data statistics, is the saved data itself a state
- 2014合肥市第三十一届青少年信息学奥林匹克竞赛(小学组)试题
- @transactional滥用导致数据源连接池耗尽问题
- mysql中explain语句查询sql是否走索引,extra中的几种类型整理汇总
- ftp、sftp文件传输
- Leetcode fizzbuzz C # answer
- Shell programming core technology "four"
- Double colon function operator and namespace explanation
- Pythagorean number law (any three numbers can meet the conditions of Pythagorean theorem)
- FTP, SFTP file transfer
猜你喜欢
Lm10 cosine wave homeopathic grid strategy
"Only one trip", active recommendation and exploration of community installation and maintenance tasks
Introduction to polyfit software
The 300th weekly match of leetcode (20220703)
用实际例子详细探究OpenCV的轮廓绘制函数drawContours()
Pointnet/Pointnet++点云数据集处理并训练
联想首次详解绿色智城数字孪生平台 破解城市双碳升级难点
大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行
Use canal and rocketmq to listen to MySQL binlog logs
Opencv functions and methods related to binary threshold processing are summarized for comparison and use
随机推荐
Pytest 可视化测试报告之 Allure
Is it safe to open an account at Great Wall Securities? How to open an account when buying stocks
Introduction to polyfit software
双冒号作用运算符以及命名空间详解
ftp、sftp文件传输
LeetCode FizzBuzz C#解答
添加命名空间声明
1003 Emergency(25 分)(PAT甲级)
Bi skills - permission axis
BCG 使用之新建向导效果
The page element is vertically and horizontally centered, realizing the vertical and horizontal centering of known or unknown width.
Shell programming core technology "four"
Oracle with as ORA-00903: invalid table name 多表报错
Reflection (I)
Allure of pytest visual test report
OpenCV的二值化处理函数threshold()详解
node_exporter部署
Some thoughts on whether the judgment point is located in the contour
.NET ORM框架HiSql实战-第二章-使用Hisql实现菜单管理(增删改查)
In flinksql, in addition to data statistics, is the saved data itself a state