Created
December 8, 2016 02:32
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
{ "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