当前位置:网站首页>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)
}
边栏推荐
- 矩阵翻转(数组模拟)
- HDU 1372 & POJ 2243 Knight Moves(广度优先搜索)
- English语法_名词 - 使用
- The page element is vertically and horizontally centered, realizing the vertical and horizontal centering of known or unknown width.
- Niuke Xiaobai month race 7 F question
- Online text line fixed length fill tool
- [QNX hypervisor 2.2 user manual]6.3.1 factory page and control page
- 一文掌握数仓中auto analyze的使用
- To sort out messy header files, I use include what you use
- 牛客小白月赛7 F题
猜你喜欢
92. (cesium chapter) cesium building layering
YOLOv5s-ShuffleNetV2
Mysql database basic operation -ddl | dark horse programmer
FPGA timing constraint sharing 01_ Brief description of the four steps
公司要上监控,Zabbix 和 Prometheus 怎么选?这么选准没错!
To sort out messy header files, I use include what you use
Several methods of online database migration
Stream stream
Chrome开发工具:VMxxx文件是什么鬼
“只跑一趟”,小区装维任务主动推荐探索
随机推荐
“只跑一趟”,小区装维任务主动推荐探索
English grammar_ Noun - use
Several methods of online database migration
Explicit random number
线上数据库迁移的几种方法
Niuke Xiaobai month race 7 e applese's super ability
kotlin 循环控制
1007 maximum subsequence sum (25 points) (PAT class a)
92. (cesium chapter) cesium building layering
黑马程序员-软件测试--08阶段2-linux和数据库-23-30-进程端口相关,修改文件权限,端口号信息的获取,程序和进程相关操作,linux命令案例
Find the nth power of 2
Stream流
BCG 使用之新建向导效果
1003 Emergency(25 分)(PAT甲级)
做社交媒体营销应该注意些什么?Shopline卖家的成功秘笈在这里!
项目中遇到的线上数据迁移方案1---总体思路整理和技术梳理
What should we pay attention to when doing social media marketing? Here is the success secret of shopline sellers!
指定输出的字符集
Technologie de base de la programmation Shell IV
添加命名空间声明