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

Lesson Complete

Play Next Lesson
Next
Save for later
About this episode
See versions
See forum comments
Cinema mode Mark as Complete Download course materials
Previous episode: 14. Challenge: Use For Loops Next episode: 16. Simplify Code with When Expressions

This video was last updated on Aug 9 2022

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a kodeco.com Professional subscription.

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()
}