当前位置:网站首页>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)
}
边栏推荐
- 升级智能开关,“零火版”、“单火”接线方式差异有多大?
- 1003 Emergency(25 分)(PAT甲级)
- 反射(一)
- HMM隐马尔可夫模型最详细讲解与代码实现
- Socket programming demo II
- 【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
- Personal thoughts on Architecture Design (this article will be revised and updated continuously later)
- node_exporter部署
- Matrix flip (array simulation)
- 生成XML元素
猜你喜欢

如何使用Async-Awati异步任务处理代替BackgroundWorker?

在线文本行固定长度填充工具

HMM隐马尔可夫模型最详细讲解与代码实现

node_exporter部署

Stream流

Opencv functions and methods related to binary threshold processing are summarized for comparison and use

FPGA timing constraint sharing 01_ Brief description of the four steps

如何使用Async-Awati异步任務處理代替BackgroundWorker?

The explain statement in MySQL queries whether SQL is indexed, and several types in extra collate and summarize

【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
随机推荐
1011 World Cup Betting (20 分)(PAT甲级)
Swagger突然发癫
Jetpack compose tutorial
OpenCV的二值化处理函数threshold()详解
在线SQL转Excel(xls/xlsx)工具
Online text line fixed length fill tool
西门子HMI下载时提示缺少面板映像解决方案
函数式接口
LeetCode FizzBuzz C#解答
Leetcode fizzbuzz C # answer
How test engineers "attack the city" (Part 2)
The explain statement in MySQL queries whether SQL is indexed, and several types in extra collate and summarize
SSRS筛选器的IN运算(即包含于)用法
牛客小白月赛7 I 新建 Microsoft Office Word 文档
Comment utiliser async awati asynchrone Task Handling au lieu de backgroundworker?
FPGA时序约束分享01_四大步骤简述
Shell 编程核心技术《二》
prometheus安装
Unity editor extends C to traverse all pictures in folders and subdirectories
与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用