Scala for loop

Scala for loop statement

import scala.collection.mutable.ArrayBuffer
def findTripletSumZero(arr: Array[Int]): Array[Array[Int]]={
    var ret=ArrayBuffer[Array[Int]]()
    var inter=ArrayBuffer[Int]()
    
    for (i<-0 until arr.length)
        for (j<-i until arr.length)
            if (j+1<arr.length)
                if (arr(i)+arr(j)+arr(j+1)==0)
                   {
                    inter+=arr(i)
                    inter+=arr(j)
                    inter+=arr(j+1)
                    ret+=inter.toArray
                    inter=ArrayBuffer[Int]()
                   }
    ret.toArray
}

Last updated