Go Syntax

Go (Golang) – Basic Syntax
Go syntax is clean, simple, and strict, which helps you write readable and error-free code. Below are the core syntax rules every beginner must know.
Structure of a Go Program
Explanation
package main→ Entry packageimport "fmt"→ Import standard libraryfunc main()→ Program starts here{}→ Code blocksNo semicolon needed (
;optional)
Comments
Variables
Using var
Type Inference
Short Declaration (:=)
Only allowed inside functions
Data Types
Basic Types
Example
Constants
Input & Output
Output
Input
Operators
Arithmetic
Comparison
Logical
Conditional Statements
if-else
if with short statement
Loops (Only for loop in Go)
Traditional loop
While-style
Infinite loop
Functions
Multiple Return Values
Arrays
Slices (More Common)
Maps
Structs
Pointers
Packages
Summary
- Simple
- Strong typing
- Built-in concurrency support
- Ideal for backend & system programming
