Go Program to print 1 to 100 without loop

We declared a recursive function in this Go program to print numbers from 1 to 100 without using for loop. Here, printNumbers(num + 1) calls the printNumbers() function recursively.

package main

import "fmt"

func printNumbers(num int) {
    if num <= 100 {
        fmt.Print(num, "\t")
        printNumbers(num + 1)
    }
}
func main() {

    number := 1
    printNumbers(number)
}
Go Program to Print 1 to 100 without loop

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.