当前位置:网站首页>Kotlin process control and circulation
Kotlin process control and circulation
2022-07-05 12:42:00 【Curious rookie】
One 、 Process control
1.if
val i = 1
if (i > 0) {
print("Big")
} else {
print("Small")
}Use if, assignment .
val i = 1
val message = if (i > 0) "Big" else "Small"
print(message)
fun getLength(text: String?): Int {
return if (text != null) text.length else 0
}Abbreviation above ,Elvis expression ;
fun getLength(text: String?): Int {
return text?.length ?: 0
}2.when
val i: Int = 1
when(i) {
1 -> print(" One ")
2 -> print(" Two ")
else -> print("i Not one nor two ")
}
val i: Int = 1
val message = when(i) {
1 -> " One "
2 -> " Two "
else -> "i Not one nor two " // If you remove this line , Will report a mistake
}
print(message)Two 、 loop
1、for
val oneToThree = 1..3
for (i in oneToThree) {
println(i)
}
for (i in 6 downTo 0 step 3) {
println(i)
}
for (i in 0..10) {
println(i) //012345678910
}
for (i in 0 until 10) {
println(i) //0123456789
}
for (i in 0..10 step 2) {
print(i) //0 2 4 6 8 10
}
// Get elements
var abc = listOf("a", "b", "c")
for (i in abc) {
print(i)
}
// Get subscript
for (index in abc.indices) {
print("$index") // 0 1 2
}
// Get elements and Subscripts
for ((index, value) in abc.withIndex()) {
print("$index:$value ") //0:a 1:b 2:c
}2、while
var i = 0
while (i <= 2) {
println(i)
i++
}
var j = 0
do {
println(j)
j++
} while (j <= 2)
边栏推荐
- Get the variable address of structure member in C language
- SENT协议译码的深入探讨
- PIP command reports an error pip is configured with locations that requires tls/ssl problems
- GPS data format conversion [easy to understand]
- Flutter2 heavy release supports web and desktop applications
- Distributed solution - Comprehensive decryption of distributed task scheduling platform - xxljob scheduling center cluster
- Pytoch through datasets Imagefolder loads datasets directly from files
- MySQL stored procedure
- Handwriting blocking queue: condition + lock
- Deep discussion on the decoding of sent protocol
猜你喜欢

Understand kotlin from the perspective of an architect

MySQL transaction

Pytoch uses torchnet Classerrormeter in meter
![[figure neural network] GNN from entry to mastery](/img/e2/bb045fb03bc255b8659f9ca7cdd26b.jpg)
[figure neural network] GNN from entry to mastery

Volatile instruction rearrangement and why instruction rearrangement is prohibited

About LDA model

The evolution of mobile cross platform technology

Add a new cloud disk to Huawei virtual machine

OPPO小布推出预训练大模型OBERT,晋升KgCLUE榜首

Redis highly available sentinel mechanism
随机推荐
MySQL function
JSON parsing error special character processing (really speechless... Troubleshooting for a long time)
GPS数据格式转换[通俗易懂]
How can beginners learn flutter efficiently?
A guide to threaded and asynchronous UI development in the "quick start fluent Development Series tutorials"
Migrate data from Mysql to neo4j database
GNN(pytorch-geometric)
Pytoch through datasets Imagefolder loads datasets directly from files
Docker configures redis and redis clusters
GPON other manufacturers' configuration process analysis
Kotlin变量
End to end neural network
Hexadecimal conversion summary
Distributed solution - Comprehensive decryption of distributed task scheduling platform - xxljob scheduling center cluster
Deep discussion on the decoding of sent protocol
Redis highly available sentinel cluster
Redis highly available slice cluster
Anaconda creates a virtual environment and installs pytorch
上午面了个腾讯拿 38K 出来的,让我见识到了基础的天花
10 minute fitness method reading notes (2/5)