当前位置:网站首页>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甲级)
- 2021 Hefei informatics competition primary school group
- 2019年蜀山区第十五届青少年信息学竞赛
- Shell 编程核心技术《四》
- 偏移量函数及开窗函数
- 1672. 最富有客户的资产总量
- English语法_名词 - 使用
- mysql中explain语句查询sql是否走索引,extra中的几种类型整理汇总
- In flinksql, in addition to data statistics, is the saved data itself a state
- LeetCode FizzBuzz C#解答
猜你喜欢

LM10丨余弦波动顺势网格策略

How to use async Awati asynchronous task processing instead of backgroundworker?

欧拉函数

Use canal and rocketmq to listen to MySQL binlog logs

92.(cesium篇)cesium楼栋分层

Stream stream

The explain statement in MySQL queries whether SQL is indexed, and several types in extra collate and summarize
Summary and sorting of 8 pits of redis distributed lock

BI技巧丨权限轴

在线SQL转Excel(xls/xlsx)工具
随机推荐
Explicit random number
BCG 使用之CBCGPProgressDlg进度条使用
1011 World Cup Betting (20 分)(PAT甲级)
The CDC of sqlserver can read the data for the first time, but it can't read the data after adding, deleting and modifying. What's the reason
FPGA时序约束分享01_四大步骤简述
Leetcode fizzbuzz C # answer
Educational Codeforces Round 22 E. Army Creation
English语法_名词 - 使用
876. 链表的中间结点
Online text line fixed length fill tool
Personal thoughts on Architecture Design (this article will be revised and updated continuously later)
How test engineers "attack the city" (Part 2)
876. Intermediate node of linked list
Bi skills - permission axis
爬虫(6) - 网页数据解析(2) | BeautifulSoup4在爬虫中的使用
Crawler (6) - Web page data parsing (2) | the use of beautifulsoup4 in Crawlers
There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks
Qt实现界面滑动切换效果
Niuke Xiaobai monthly race 7 I new Microsoft Office Word document
有关架构设计的个人思考(本文后续不断修改更新)