Scala Int until(end: Int, step: Int) method with example
The until(end: Int, step: Int) method is utilized to return a range from the start value to exact previous value of specified end integer value. Here the range’s values are jumping by step value.
Method Definition: defuntil(end: Int, step: Int): collection.immutable.Range
Return Type: It returns the range.
Example #1:
// Scala program of Int until() // method // Creating object object GfG { // Main method def main(args : Array[String]) { // Applying until method val result = ( 10 ).until( 17 , 2 ) // Displays output println(result) } } |
Output:
Range(10, 12, 14, 16)
Example #2:
// Scala program of Int until() // method // Creating object object GfG { // Main method def main(args : Array[String]) { // Applying until method val result = ( 1 ).until( 12 , 3 ) // Displays output println(result) } } |
Output:
Range(1, 4, 7, 10)
Please Login to comment...