Skip to content

Latest commit

 

History

History
43 lines (37 loc) · 1.05 KB

loop.md

File metadata and controls

43 lines (37 loc) · 1.05 KB

Loop in Golang


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)
                }
          }

Note

  • 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.

SYNTAX:

    for initalization; condition; increment/decrement{
    statement to execute repitedliy
    }

EXAMPLE:

        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.