Programming in Kotlin: Fundamentals

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

Part 2: Manage Control Flow

14. Challenge: Use For Loops

Lesson Complete

Play Next Lesson
Save for later
About this episode
See versions
See forum comments
Cinema mode Mark as Complete Download course materials
Previous episode: 13. Work with For Loops Next episode: 15. Learn more Loop Features

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 Professional subscription.

Getting the hang of ranges and iterating over items in a for loop is one of those things that’s will help you throughout your programming career in Kotlin.

Challenge 1:
Create a range of 20 numbers, and iterate over it, printing out the numbers.

Challenge 2:
Iterate over the range in Challenge 1 again, but print every third number.

Challenge 3:
Create a decreasing range of 15 numbers, and print every second number.
val range = 11..30

for(number in range) {
  print("$number ")
val range = 11..30

for(number in range step 3) {
  print("$number ")
val reverseRange = 30 downTo 16

for(number in reverseRange step 2) {
  print("$number ")