‫Welcome back.
‫In Kotlin, a range is a fundamental concept that represents an interval between two values.
‫Ranges are typically used in various scenarios such as looping, slicing, or defining limits, and
‫they are a convenient way to work with a sequence of values within a specific range.
‫Kotlin provides two types of ranges closed ranges and half open ranges.
‫A closed range is defined using the two dots operator.
‫It includes both the start and end values.
‫For example, I can define a new range using a new variable equals to one, two, two dots, and to
‫five defines a closed range from 1 to 5.
‫It's used to represent a range that spans from the start value to the end value, both inclusive.
‫The general syntax for creating a closed range is start value two dots and the end value.
‫The range includes one, two, three, four, and five.
‫A half open range is defined using the until function or the two dot operators in combination with the
‫exclude end function.
‫It includes the start value, but excludes the end value.
‫For example, val range two equals to one until five.
‫It's often used for looping, as it allows you to iterate from the start value up, but not including
‫the end value.
‫The syntax for creating a half open range with until is start value.
‫Until end value.
‫I'll print these ranges, and in order to iterate through a specific range, I need to use a for loop.
‫So ranges in Kotlin are often used in for loops when working with collections or when defining constants
‫for variables.
‫For example, you can use a range to iterate over a specific range of numbers or access a portion of
‫an array.
‫So if I need to print a range, I in range which is 1 to 5, I need to write like this print ln and
‫print I.
‫Let me run the program and here we go from 1 to 5 and five is inclusive.
‫If I use range two which is half open range run the program.
‫I can see it.
‫Prints from one, two, four, five is not included.
‫This is the difference between until and.
‫The two dots operator ranges make it easier to work with a specific sequence of values within a specific
‫interval, and they are a convenient tool for many programming tasks in Kotlin.