当前位置:网站首页>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)
}
边栏推荐
- Leetcode fizzbuzz C # answer
- 反射(一)
- 爬虫(6) - 网页数据解析(2) | BeautifulSoup4在爬虫中的使用
- "Only one trip", active recommendation and exploration of community installation and maintenance tasks
- Shell 編程核心技術《四》
- 线上数据库迁移的几种方法
- 2021 Hefei informatics competition primary school group
- 双冒号作用运算符以及命名空间详解
- Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
- C# 使用StopWatch测量程序运行时间
猜你喜欢
YOLOv5s-ShuffleNetV2
Hough Transform 霍夫变换原理
English grammar_ Noun - use
Bi skills - permission axis
如何使用Async-Awati异步任务处理代替BackgroundWorker?
Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?
2022CoCa: Contrastive Captioners are Image-Text Fountion Models
【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
FPGA timing constraint sharing 01_ Brief description of the four steps
Pytorch学习(四)
随机推荐
Mysql database basic operation -ddl | dark horse programmer
Personal thoughts on Architecture Design (this article will be revised and updated continuously later)
1007 Maximum Subsequence Sum(25 分)(PAT甲级)
1672. Total assets of the richest customers
Jetpack compose tutorial
English grammar_ Noun - use
Opencv functions and methods related to binary threshold processing are summarized for comparison and use
矩阵翻转(数组模拟)
基于NCF的多模块协同实例
线上数据库迁移的几种方法
2021 Hefei informatics competition primary school group
Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
双冒号作用运算符以及命名空间详解
26. 删除有序数组中的重复项 C#解答
1006 Sign In and Sign Out(25 分)(PAT甲级)
MySQL数据库基本操作-DDL | 黑马程序员
Shell programming core technology "I"
明明的随机数
勾股数规律(任意三个数能够满足勾股定理需要满足的条件)
1003 Emergency(25 分)(PAT甲级)