I will create several articles for you to learn Go by examples. These examples are commented. Read the comments to learn the syntax then execute on-line using: https://go.dev/play.
// any program has a package main
package main
// fmt is a Go standard package
import "fmt"
// main function is mandatory
func main() {
// public functions start with uppercase
fmt.Println("Hello, World")
}
/* Notes:
1. End of statement do not use semicolumn
2. Go syntax is similar to C/C++
3. Go do not support nested comments
*/
Run it: https://go.dev/play/p/r4GvaOvPp_9
Note: These executable links are secret, don't publish them anywhere else. If you wish, refer my entire blog series to your friends so that they can learn with you.
In this example we have learned:
Line comments start with //
Block comments are enclosed in /* ... */
Block of code is enclosed in curly brackets { ... }
The semicolon at the end of the line is optional in GO
Function fmt.Println() start with capital letter
Thank you for reading. If you like this article, give me a vote and encourage me to write more. Life is short, I don't want to waste my time if you don't like it.
Have fun, learn and prosper ๐๐๐ผ