33 lines
521 B
Go
33 lines
521 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
func main() {
|
|
fmt.Println("There is no parantheses in for loop unlike other languages")
|
|
fmt.Println("braces are necessary in for loop")
|
|
|
|
/* SYNTAX:
|
|
for INIT; CONDITION; POST {
|
|
|
|
}
|
|
*/
|
|
|
|
sum := 0
|
|
for i := 0; i < 10; i++ {
|
|
sum += i
|
|
}
|
|
fmt.Println(sum)
|
|
|
|
fmt.Println("Init and post statements are optional\nSo you can use for loop as while in other languages")
|
|
|
|
val := 100
|
|
for val > 0 {
|
|
val -= 1
|
|
}
|
|
fmt.Println(val)
|
|
|
|
fmt.Println("break and continue keywords are same as C")
|
|
|
|
}
|