golang loop
package main
import "fmt"
func main() {
sum := 0
for i := 0; i < 10; i++ {
sum += i
}
fmt.Println(sum)
}
golang loop
package main
import "fmt"
func main() {
sum := 0
for i := 0; i < 10; i++ {
sum += i
}
fmt.Println(sum)
}
golang while loop
package main
import "fmt"
func main(){
//only one type of look in golang. A for loop. to make a while loop simple
//emit all statments but the bools
var x int = 10
for x > 0{
fmt.Println(x)//this will print all numbers from 10-1
x--//decrement the x to make it go down by one each loop
}
}
go while
C's while is spelled for in Go.
package main
import "fmt"
func main() {
sum := 1
for sum < 1000 {
sum += sum
}
fmt.Println(sum)
}
while in golang
package main
import "fmt"
func main() {
sum := 1
for sum < 10 {
fmt.Println(sum)
sum++
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us