TheBulgarianWolf

Kotlin_Continue

Mar 17th, 2021
963
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.60 KB | None | 0 0
  1. fun main(args: Array<String>) {
  2.  for (i in 1..5) {
  3.     println("$i Always printed.")
  4.     if (i > 1 && i < 5) {
  5.         continue
  6.     }
  7.     println("$i Not always printed.")
  8.  }
  9.  
  10.     var number: Int
  11.     var sum = 0
  12.  
  13.     for (i in 1..6) {
  14.         print("Enter an integer: ")
  15.         number = readLine()!!.toInt()
  16.  
  17.         if (number <= 0)
  18.             continue
  19.  
  20.         sum += number
  21.     }
  22.     println("sum = $sum")
  23.  
  24.     here@ for (i in 1..5) {
  25.         for (j in 1..4) {
  26.             if (i == 3 || j == 2)
  27.                 continue@here
  28.             println("i = $i; j = $j")
  29.         }
  30.     }
  31. }
Add Comment
Please, Sign In to add comment