package main
import "fmt"
// Main func to run code
func main(){
//For loop
for i:=1; i<100;i++{
// statement to execute repitedly
fmt.Println("Hello World! ",i)
}
}
- In Go programming languge their is only one loop
such as for loop
if we have to exceuter a block of code repetedly then we will use for loop.
along with for keyword initalze varable put semicolon put condition again semicolon;
and increment or decrement.
Why we use semicolon ? -> To sepretout the conditions.
for initalization; condition; increment/decrement{
statement to execute repitedliy
}
for i := 1; i<=10; i++{
fmt.Println("Hello World! ",i)
}
- To get code file click hear
and clone locally.
and run using
go run loop.go
Note: You must have installed Golnag in your system.