Programming in Kotlin: Fundamentals

Aug 9 2022 · Kotlin 1.6, Android 12, IntelliJ IDEA CE 2022.1.3

Part 2: Manage Control Flow

15. Learn more Loop Features

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 14. Challenge: Use For Loops Next episode: 16. Simplify Code with When Expressions

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

So far you’ve used loops to iterate over ranges.

for (num in 0..14) {
  println(num)
}
for (num in 0..14) {
  if (num%2 == 0) {
    continue
  }
  
  println(num)
}
for (num in 0..14) {
  if (num%2 == 0) {
    continue
  }

  println(num)

  if (num == 7) {
    println("Get some rest")
    break
  }
}
for (row in 0..5) {
  for (column in 0..5) {
    print("x\t")
  }
  println()
}
row@ for (row in 0..5) {
...
}
row@ for (row in 0..5) {
  column@ for (column in 0..5) {
    print("x\t")
  }
  println()
}
row@ for (row in 0..5) {
  column@ for (column in 0..5) {
    if (column == 2 && row == 2) {
      break@column
    }
    print("x\t")
  }
  println()
}
row@ for (row in 0..5) {
  column@ for (column in 0..5) {
    if (column == 2 && row == 2) {
      break@row
    }
    print("x\t")
  }
  println()
}