165 lines
3.3 KiB
Plaintext
Vendored
165 lines
3.3 KiB
Plaintext
Vendored
public static class ControlStructures {
|
|
public fun <init>()
|
|
|
|
public immutable var prop: Int = 3
|
|
|
|
public fun nullFun(): String? = null
|
|
|
|
public fun test(): Boolean {
|
|
" "
|
|
"Z"
|
|
"Z Z"
|
|
'c'
|
|
5
|
|
5.0
|
|
5.0
|
|
-5
|
|
+5
|
|
0.0
|
|
-0.0
|
|
1.0E10
|
|
1.0E-10
|
|
public immutable var qwe: Int = 2
|
|
|
|
" " + qwe + " "
|
|
"a" + "\"" + "b"
|
|
"a'b" + "\r" + "\n"
|
|
"5" + "\n" + " 2"
|
|
"\t" + "\t" + "\t"
|
|
if (5 > 3) {
|
|
println("5 > 3")
|
|
}
|
|
|
|
for (c : "ABC") {
|
|
println(c)
|
|
}
|
|
|
|
for (c : "DEF") {
|
|
println(c.toByte())
|
|
}
|
|
|
|
public var i: Int = 5
|
|
|
|
while (i > 0) {
|
|
i--
|
|
if (i == 3) break
|
|
if (i == 2) {
|
|
continue
|
|
}
|
|
|
|
}
|
|
|
|
"" !is String
|
|
("" as Any) as String?
|
|
super.equals(this)
|
|
this.equals(this)
|
|
this.equals(this)
|
|
ControlStructures::test
|
|
ControlStructures::prop
|
|
ControlStructures::class.java
|
|
outer@ for (outerVal : 1 .. 2) {
|
|
inner@ for (innerVal : 3 .. 4) {
|
|
continue@outer
|
|
}
|
|
|
|
break@outer
|
|
}
|
|
|
|
nullFun()?.let({
|
|
println(it)
|
|
})
|
|
i = 5
|
|
do {
|
|
i -= 1
|
|
}
|
|
while (i > 0)
|
|
|
|
"ABC".forEach({
|
|
println(it.toString()[0])
|
|
})
|
|
"ABC".zip("DEF").forEach({
|
|
println(it.first + " " + it.second)
|
|
})
|
|
public immutable var arr: Array<String> = arrayOf("A", "B", "C")
|
|
|
|
println(arr[2])
|
|
local var var1496943053: <error> = "ABC".zip("DEF")
|
|
local immutable var a: Pair<Char, Char> = var1496943053.component1()
|
|
local immutable var b: Pair<Char, Char> = var1496943053.component2()
|
|
public immutable var value: String = if (5 > 3) "a" else "b"
|
|
|
|
public immutable var list: List<String> = listOf("A")
|
|
|
|
public immutable var list2: List<String> = listOf("A")
|
|
|
|
public immutable var type: String = switch (value) {
|
|
it in list -> {
|
|
"inlist"
|
|
break
|
|
}
|
|
|
|
it in list2 -> {
|
|
"notinlist2"
|
|
break
|
|
}
|
|
|
|
it is String -> {
|
|
"string"
|
|
break
|
|
}
|
|
|
|
it is CharSequence -> {
|
|
"cs"
|
|
break
|
|
}
|
|
|
|
-> {
|
|
"unknown"
|
|
break
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public immutable var x: String = switch {
|
|
value == "b" -> {
|
|
"B"
|
|
break
|
|
}
|
|
|
|
5 % 2 == 0 -> {
|
|
println("A")
|
|
"Q"
|
|
break
|
|
}
|
|
|
|
false -> {
|
|
"!"
|
|
break
|
|
}
|
|
|
|
-> {
|
|
"A"
|
|
break
|
|
}
|
|
|
|
}
|
|
|
|
|
|
try {
|
|
5 + 1
|
|
throw <init>()
|
|
}
|
|
catch (e) {
|
|
e.printStackTrace()
|
|
}
|
|
catch (e) {
|
|
System.out.println("error!")
|
|
}
|
|
finally {
|
|
System.out.println("finally")
|
|
}
|
|
return false
|
|
}
|
|
}
|