golang while loop
while (condition):
doThis();
4.25
9
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
}
}
Thank you!
9
0
3.5
9
package main
import "fmt"
func main() {
sum := 1
for sum < 10 {
fmt.Println(sum)
sum++
}
}
Thank you!
9
0
4.17
6
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!
6
0
0
1
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!
1
0
Are there any code examples left?
New code examples in category Go
-
Go 2022-03-27 22:30:23 golang check if ip is v6
-
Go 2022-03-27 16:20:18 make image go to center of page
-
Go 2022-03-24 15:20:01 why does my discord bot not work when i take code from googl
-
Go 2022-03-21 18:40:22 pass method as props vue
-
Go 2022-03-19 23:40:33 reverse a string in golang
-
Go 2022-03-17 19:30:08 instancing in godot
-
Go 2022-03-17 09:55:17 brew upgrae golang-migrate
-
Go 2022-03-17 06:15:06 Tushar Jadhav
-
Go 2022-03-17 00:00:12 golang cwd