Skip to content
Related Articles

Related Articles

Scala Int to(end: int, step: int) method with example
  • Last Updated : 30 Jan, 2020
GeeksforGeeks - Summer Carnival Banner

The to(end: int, step: int) method is utilized to return a range from the stated integer to the ‘end’, which is given in the arguments list and some step is also specified in the arguments list.

Method Definition: def to(end: Int, step: Int): Inclusive

Return Type: It returns the range.

Example #1:




// Scala program of Int to() 
// method 
    
// Creating object 
object GfG 
{  
    
    // Main method 
    def main(args:Array[String]) 
    
        // Applying to() method  
        val result = 5.to(10, 2
            
        // Displays output 
        println(result) 
            
    
}  
Output:



Range(5, 7, 9)

Example #2:




// Scala program of Int to() 
// method 
// Creating object 
object GfG 
{  
    
    // Main method 
    def main(args:Array[String]) 
    
        // Applying to() method 
        val result = (0).to(9, 3
            
        // Displays output 
        println(result) 
            
    
}  
Output:
Range(0, 3, 6, 9)

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :