go language 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
}
}
4.13
8
C's while is spelled for in Go.
package main
import "fmt"
func main() {
sum := 1
for sum < 1000 {
sum += sum
}
fmt.Println(sum)
}
Thank you!
8
0
0
0
package mainimport "fmt"func main() { i := 1 max := 20 // technically go doesnt have while, but // for can be used while in go. for i < max { fmt.Println(i) i += 1 }}
Thank you!
0
0
Are there any code examples left?
New code examples in category Other