Open In App

Scala | Ranges

The Range in Scala can be defined as an organized series of uniformly separated Integers. It is helpful in supplying more strength with less methods so, operations performed here are very quick.
 
Some important points:

Syntax:



val range = Range(x, y, z)

Where, x is the lower limit, y is the upper limit, and z is the increment.
Example:




// Scala program for Ranges
  
// Creating object
object GFG
{
  
    // Main method
    def main(args: Array[String])
    {
  
        // applying range method
        val x = Range(3, 10, 1)
  
        // Displays given range
        println(x)
  
        // Displays starting value
        // of the given range
        println(x(0))
  
        // Displays last value
        // of the given range
        println(x.last)
    }
}

Output:
Range(3, 4, 5, 6, 7, 8, 9)
3
9

Thus, we can say that upper bound of the Range is not inclusive.



Operations performed on Ranges


Article Tags :