04-statements

AdSense Placeholder (Header)
Go Tutorials Beginner

Understanding Statements in Go

Programs are built from statements — individual instructions that tell your computer what to do, one step at a time.

Also available on YouTube Playlist

What Is a Statement?

A statement is simply one complete instruction in your program. When you write fmt.Println("Hello"), that's a statement. When you write x := 5, that's a statement too. Your entire program is just a sequence of statements executed one after another, top to bottom.

Types of Statements You'll See

Assignment Statements

These store values into variables:

name := "Bits Bytes"   // short declaration + assignment
age = 30               // simple assignment

Expression Statements

These call a function or evaluate something:

fmt.Println("Learning Go!")
time.Sleep(2 * time.Second)

Return Statements

These send a value back from a function:

func add(a int, b int) int {
    return a + b
}

You'll learn more about functions in lessons 08 and 09, but for now just know that return is how a function hands its result back to whoever called it.

One nice thing about Go: You don't need semicolons at the end of lines. Go adds them automatically during compilation. One less thing to worry about.

Blocks — Grouping Statements Together

Curly braces { } group statements into blocks. Every function body is a block. Every if-else body is a block. This keeps your code organized and tells Go which statements belong together:

func main() {
    // This entire block runs when your program starts
    greeting := "Welcome!"
    fmt.Println(greeting)
}

The key idea: statements run in order, and blocks define scope — meaning variables created inside a block only exist within that block.

Try It Yourself

Write a small program with at least 5 different statements: declare two variables, print them, change one of them, and print again. Notice how each line is an instruction that Go follows in sequence.

✅ Step 4 of 11 Completed
Phase 1: Go Foundations
📝