Open In App

Scala Int to(end: int, step: int) method with example

Last Updated : 30 Jan, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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)


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads