34 followers 0 articles/week
print a, aa, aaa

package main import ( "fmt" "time" ) func main() { s := "a" for ; s != "aaaaa"; { fmt.Println(s) s = s + "a" time.Sleep(1000 * time.Millisecond) } } Prints... a aa aaa aaaa Here's a different way of doing this that I found on stackoverflow... package main import ( "fmt" "bytes" ) func main() {...

Fri Jan 3, 2014 03:12
break - an example

package main import ( "fmt" "time" ) func main() { s := 0 for { if s >= 5 { break } fmt.Println("s is:", s) s++ time.Sleep(1000 * time.Millisecond) } fmt.Println("Break happened") } ...and you get: s is: 0 s is: 1 s is: 2 s is: 3 s is: 4 Break happened

Fri Jan 3, 2014 03:12
string.length in go

package main import "fmt" func main() { words := "hello world" fmt.Println(len(words)) }

Fri Jan 3, 2014 03:12
string.count in go

package main import ( "fmt" "strings" ) func main() { words := "hello world" fmt.Printf("Number of l's in %s is: ", words) fmt.Printf("%d\n", strings.Count(words, "l")) }

Fri Jan 3, 2014 03:12
write unicode character

To write a Unicode-character in code preface the hexadecimal value with \u or \U. Because they need at least 2 bytes we have to use the int16 or int type. If 4 bytes are needed for the character \U is used; \u is always followed by exactly 4 hexadecimal digits and \U by 8 . package main import "fmt" func main() { ch := '\u0041' ch2 := '\u03B2'...

Fri Jan 3, 2014 03:12
math.Pow

package main import ( "fmt" "math" ) func main() { var xpow, ypow, mynum float64 xpow = 10 ypow = 2 mynum = math.Pow(xpow, ypow) fmt.Printf("you get %g\n", mynum) } // you get 100

Fri Jan 3, 2014 03:12

Build your own newsfeed

Ready to give it a go?
Start a 14-day trial, no credit card required.

Create account