TheBulgarianWolf

Kotlin While_DoWhile

Mar 15th, 2021
846
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fun main(args: Array<String>) {
  2.     var sum1 = 0
  3.     var i1 = 100
  4.  
  5.     while (i1 != 0) {
  6.         sum1 += i1     // sum = sum + i;
  7.         --i1
  8.     }
  9.     println("sum = $sum1")
  10.  
  11.     var sum: Int = 0
  12.     var input: String
  13.  
  14.     do {
  15.         print("Enter an integer: ")
  16.         input = readLine()!!
  17.         sum += input.toInt()
  18.  
  19.     } while (input != "0")
  20.  
  21.     println("sum = $sum")
  22. }
RAW Paste Data