Skip to content

Instantly share code, notes, and snippets.

@hygull
Created December 8, 2016 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hygull/564a67122f359d6b8f30193e37b28c8a to your computer and use it in GitHub Desktop.
Save hygull/564a67122f359d6b8f30193e37b28c8a to your computer and use it in GitHub Desktop.
Golang - 3 different forms of for loop created by hygull - https://repl.it/Eifo/9
/*
{ "Date of creation" => "07 Dec 2016 (Started after 06:45 am)" }
{ "Aim of program" => "To use 3 different forms of for loop" }
{ "Coded by" => "Rishikesh Agrawani" }
{ "Go version" => "1.7" }
*/
package main
import "fmt"
func main() {
//1st form.......................
i := 1
for i <= 10 {
fmt.Printf("%d ", i)
i+=1
}
fmt.Println() //To add newline...
//2nd form.......................
j := 1
for {
if j <= 10 {
fmt.Printf("%d ", j)
j += 1
continue
}
break
}
fmt.Println()
//3rd form.....................
for k := 1; k <= 10; k += 1 {
fmt.Print(k, " ")
}
fmt.Println()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment