当前位置:网站首页>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)
}
边栏推荐
- kotlin 条件控制
- Educational Codeforces Round 22 E. Army Creation
- .NET ORM框架HiSql实战-第二章-使用Hisql实现菜单管理(增删改查)
- 1008 Elevator(20 分)(PAT甲级)
- prometheus安装
- In flinksql, in addition to data statistics, is the saved data itself a state
- PointNeXt:通过改进的模型训练和缩放策略审视PointNet++
- HDU 1372 & POJ 2243 Knight moves (breadth first search)
- To sort out messy header files, I use include what you use
- Have you guys ever used CDC direct Mysql to Clickhouse
猜你喜欢
Hough transform Hough transform principle
English grammar_ Noun - use
92.(cesium篇)cesium楼栋分层
Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?
The 300th weekly match of leetcode (20220703)
2022CoCa: Contrastive Captioners are Image-Text Fountion Models
Pointnet/Pointnet++点云数据集处理并训练
Lm10 cosine wave homeopathic grid strategy
Detailed explanation of the binary processing function threshold() of opencv
【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
随机推荐
HDU 1372 & POJ 2243 Knight Moves(广度优先搜索)
How to use async Awati asynchronous task processing instead of backgroundworker?
QT realizes interface sliding switching effect
Several methods of online database migration
node_exporter部署
【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
FPGA时序约束分享01_四大步骤简述
在线SQL转Excel(xls/xlsx)工具
牛客小白月赛7 I 新建 Microsoft Office Word 文档
Use canal and rocketmq to listen to MySQL binlog logs
BCG 使用之CBCGPProgressDlgCtrl进度条使用
876. Intermediate node of linked list
如何使用Async-Awati异步任务处理代替BackgroundWorker?
大div中有多个div,这些div在同一行显示,溢出后产生滚动条而不换行
页面元素垂直水平居中、实现已知或者未知宽度的垂直水平居中。
1005 Spell It Right(20 分)(PAT甲级)
Online data migration scheme encountered in the project 1 - general idea sorting and technical sorting
1009 Product of Polynomials(25 分)(PAT甲级)
English grammar_ Noun - use
2021 合肥市信息学竞赛小学组