PHP       WEB       3GL   4GL   5GL      

Kotlin

Kotlin

If

Kotlin, if , .. . ( ? : ), if .

//   
var max = a 
if (a < b) 
  max = b 
 
//   else 
var max: Int
if (a > b) 
  max = a 
else 
  max = b 
 
//    
val max = if (a > b) a else b

"" if , :

val max = if (a > b) { 
    print(" a") 
    a 
  } 
  else { 
    print(" b") 
    b 
  }

if (, ), else .

. if.

when

when switch, C- .

when (x) {
  1 -> print("x == 1")
  2 -> print("x == 2")
  else -> { //    
    print("x is neither 1 nor 2")
  }
}

when . when , . , , . , . ( if: .)

else , . when , else , , , .

, :

when (x) {
  0, 1 -> print("x == 0 or x == 1")
  else -> print("otherwise")
}

when (x) {
  parseInt(s) -> print("s encodes x")
  else -> print("s does not encode x")
}

in !in :

when (x) {
  in 1..10 -> print("x is in the range")
  in validNumbers -> print("x is valid")
  !in 10..20 -> print("x is outside the range")
  else -> print("none of the above")
}

otlin is or !is . , smart casts, .

val hasPrefix = when(x) {
  is String -> x.startsWith("prefix")
  else -> false
}

when if-else if. , , :

when {
  x.isOdd() -> print("x is odd")
  x.isEven() -> print("x is even")
  else -> print("x is funny")
}

. when.

for

for , . :

for (item in collection)
  print(item)

:

for (item: Int in ints) {
  // ...
}

, for , , :

operator.

, :

for (i in array.indices)
  print(array[i])

, " " .

withIndex:

for ((index, value) in array.withIndex()) {
    println("the element at $index is $value")
}

. for.

while

while and do..while :

while (x > 0) {
  x--
}

do {
  val y = retrieveData()
} while (y != null) // y is visible here!

. while.

break continue

Kotlin break continue . . .

  PHP       WEB       3GL   4GL   5GL         w  

, - , , , .




 10.11.2021 - 12:37: - Personalias -> WHO IS WHO - - _.
10.11.2021 - 12:36: - Conscience -> . ? - _.
10.11.2021 - 12:36: , , - Upbringing, Inlightening, Education -> ... - _.
10.11.2021 - 12:35: - Ecology -> - _.
10.11.2021 - 12:34: , - War, Politics and Science -> - _.
10.11.2021 - 12:34: , - War, Politics and Science -> . - _.
10.11.2021 - 12:34: , , - Upbringing, Inlightening, Education -> , - _.
10.11.2021 - 09:18: - New Technologies -> , 5G- - _.
10.11.2021 - 09:18: - Ecology -> - _.
10.11.2021 - 09:16: - Ecology -> - _.
10.11.2021 - 09:15: , , - Upbringing, Inlightening, Education -> - _.
10.11.2021 - 09:13: , , - Upbringing, Inlightening, Education -> - _.
Bourabai Research -  XXI Bourabai Research Institution