Print the pattern without for loop

Eg: 16 11 6 1 -4 1 6 11 16Eg: 15 10 5 0 5 10 15
package mainimport (
"fmt"
"strconv"
)
func printPattern(num, curNum, decFactor int) {
if decFactor < 0 && curNum > num {
return
}
fmt.Print(strconv.Itoa(curNum) + " ")
if curNum <= 0 {
decFactor = -1 * decFactor
}
curNum = curNum - decFactor
printPattern(num, curNum, decFactor)
}
func main() {
printPattern(15, 15, 5)
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store