当前位置:网站首页>Kotlin cycle control
Kotlin cycle control
2022-07-04 19:42: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)
}
边栏推荐
猜你喜欢
C # use stopwatch to measure the running time of the program
记一次 .NET 某工控数据采集平台 线程数 爆高分析
Detailed explanation of the binary processing function threshold() of opencv
Pointnet/Pointnet++点云数据集处理并训练
TCP waves twice, have you seen it? What about four handshakes?
黑马程序员-软件测试--09阶段2-linux和数据库-31-43修改文件权限字母发的说明,-查找链接修改文件,查找文件命令,链接文件,压缩解压方式,vi编辑器基本使用,
To sort out messy header files, I use include what you use
English语法_名词 - 使用
【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
如何使用Async-Awati异步任务处理代替BackgroundWorker?
随机推荐
1011 World Cup Betting (20 分)(PAT甲级)
Euler function
在线SQL转Excel(xls/xlsx)工具
欧拉函数
How to use async Awati asynchronous task processing instead of backgroundworker?
92.(cesium篇)cesium楼栋分层
Socket programming demo II
Jetpack compose tutorial
1002. A+b for Polynomials (25) (PAT class a)
The kth largest element in the array
Shell programming core technology "three"
黑马程序员-软件测试--08阶段2-linux和数据库-23-30-进程端口相关,修改文件权限,端口号信息的获取,程序和进程相关操作,linux命令案例
Find the nth power of 2
Niuke Xiaobai month race 7 who is the divine Archer
The page element is vertically and horizontally centered, realizing the vertical and horizontal centering of known or unknown width.
Shell 编程核心技术《四》
BCG 使用之CBCGPProgressDlgCtrl进度条使用
Master the use of auto analyze in data warehouse
Online sql to excel (xls/xlsx) tool
牛客小白月赛7 E Applese的超能力