Page History

制御構文

yhornisse edited this page on 15 Feb 2020

Clone this wiki locally

制御構文

https://kotlinlang.org/docs/reference/control-flow.html

if

if (s.equals("hoge")){
  println(1)
} else if (s.equals("fuga")){
  println(2)
} else {
  println(3)
}
var s:String = "fuga"
var i:Int = if (s.equals("hoge")) 1 else 2
println(i)

when

var s:String = "fuga"
when(s){
      "hoge", "fuga" -> println(1)
      else -> println(2)
}
var s:String = "fuga"
var i:Int = when(s){
      "hoge", "fuga" -> 1
      else -> 2
}
println(i)

for

foreach

for-in

while

break・continue

  • break
  • continue
  • ラベル付きbreak
  • ラベル付きcontinue