当前位置:网站首页>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)
边栏推荐
- Storage Basics
- Distributed solution - Comprehensive decryption of distributed task scheduling platform - xxljob scheduling center cluster
- Clear neo4j database data
- Master the new features of fluent 2.10
- GNN(pytorch-geometric)
- GPS數據格式轉換[通俗易懂]
- The evolution of mobile cross platform technology
- Constructing expression binary tree with prefix expression
- Using docker for MySQL 8.0 master-slave configuration
- Correct opening method of redis distributed lock
猜你喜欢

Pytoch monolayer bidirectional_ LSTM implements MNIST and fashionmnist data classification

Making and using the cutting tool of TTF font library

Learn the memory management of JVM 02 - memory allocation of JVM

从39个kaggle竞赛中总结出来的图像分割的Tips和Tricks

Anaconda creates a virtual environment and installs pytorch

Pytoch loads the initialization V3 pre training model and reports an error

Third party payment interface design

Pytoch implements tf Functions of the gather() function

Constructing expression binary tree with prefix expression

UNIX socket advanced learning diary - advanced i/o functions
随机推荐
Xi IO flow
ZABBIX monitors mongodb (template and deployment operations)
Take you two minutes to quickly master the route and navigation of flutter
MySQL constraints
GPS數據格式轉換[通俗易懂]
A guide to threaded and asynchronous UI development in the "quick start fluent Development Series tutorials"
Common commands and basic operations of Apache Phoenix
Making and using the cutting tool of TTF font library
Pytoch counts the number of the same elements in the tensor
Flume common commands and basic operations
Get the variable address of structure member in C language
MySQL data table operation DDL & data type
MySQL index - extended data
JDBC -- extract JDBC tool classes
激动人心!2022开放原子全球开源峰会报名火热开启!
Take you hand in hand to develop a service monitoring component
GPS data format conversion [easy to understand]
Implementing Yang Hui triangle with cyclic queue C language
Pytoch implements tf Functions of the gather() function
GPON other manufacturers' configuration process analysis